Page 1 of 1

Show PDF in servoy webclient

PostPosted: Tue Jul 14, 2009 4:30 pm
by Rene van Veen
Hello,

I have found a way to show PDF in Servoy Webclient.
I show the PDF in a embedded PDF reader. (this works on Windows and MAC OSX)

How to:

1. Create a global variable and define it as a Media field
2. Place the variable on a form and set the displayType to "HTML_AREA"

With the following code you can show a PDF in this HTML_AREA:

Code: Select all
globals.variable = "<embed src=\"/PATH/TO/PDF/FILE.pdf#toolbar=1&navpanes=0\" width=\"100%\" height=\"100%\"></embed>"


I have tested this with Servoy 4.1.3 on the following browsers
Windows:
    Firefox
    IE Explorer

MAC OSX:

Kind Regards,

René van Veen
Ambitius

Re: Show PDF in servoy webclient

PostPosted: Thu Jul 16, 2009 11:20 pm
by Westy
Nice.

<embed> tag is new in HTML 5.

Dean

Re: Show PDF in servoy webclient

PostPosted: Mon Jun 21, 2010 1:43 pm
by Foobrother
Hi,

I'm trying to use this code but it doesn't work for me. I'm getting the picture icon instead of the Adobe Reader panel.
I have a globals variable of type MEDIA which is the dataprovider of the HTML_AREA in the form displaying the pdf.

I set the global like that just before showing the form:
Code: Select all
var pdfURL = "C:\\Program Files\\Servoy\\application_server\\server\\webapps\\ROOT\\pdf_viewer\\test.pdf"
globals.g_pdf_viewer_file = "<embed src=\""+pdfURL+"#toolbar=1&navpanes=0\" width=\"100%\" height=\"100%\"></embed>";


globals.g_pdf_viewer_file contains the following just before being used in the form:
<embed src="C:\Program Files\Servoy\application_server\server\webapps\ROOT\pdf_viewer\test.pdf#toolbar=1&navpanes=0" width="100%" height="100%"></embed>


Obviously the file exists and the path is correct.
Any idea?

I use Servoy 5.1.4 and IE 8

Re: Show PDF in servoy webclient

PostPosted: Mon Jun 21, 2010 2:29 pm
by Harjo

Re: Show PDF in servoy webclient

PostPosted: Mon Jun 21, 2010 4:16 pm
by ptalbot
Westy wrote:<embed> tag is new in HTML 5.

Not really. It is recognized by most browsers compatible with HTML 3.2.
Although up till now it was not part of the official specs of 3.2 or 4 by the W3C which was recommending using <object> instead.

Re: Show PDF in servoy webclient

PostPosted: Mon Jun 21, 2010 4:31 pm
by Foobrother
Yes indeed! That was the problem.
I thought it would work as I was on Developer (same machine).

Thx

Re: Show PDF in servoy webclient

PostPosted: Thu Oct 14, 2010 2:25 pm
by nromeou
Hi everybody,

Has anybody tested this in SmartClient??

Also with Servoy 5.x??

Thanks for the help
Cheers

Re: Show PDF in servoy webclient

PostPosted: Thu Oct 14, 2010 3:47 pm
by Harjo
the tip here, was specially ment for webclient!!
to open a pdf (or any other file!) on smartclient you just can do this:

Code: Select all
function openFile(vFilePath)
{
    vFilePath =  plugins.file.convertToJSFile(vFilePath)
    if(vFilePath.exists()) {
        application.setStatusText('<html><b>Opening file: ' + vFilePath.getName() + ' Please wait....</b></html>')
        application.updateUI()
        //windows
        if (utils.stringMiddle(application.getOSName(), 1, 7) == "Windows") {
            application.executeProgram('rundll32', 'url.dll,FileProtocolHandler', vFilePath)
        }
        //FreeBSD or Linux
        else if (utils.stringMiddle(application.getOSName(), 1, 7) == "FreeBSD" || utils.stringMiddle(application.getOSName(), 1, 5) == "Linux") {
            application.executeProgram('mozilla', vFilePath)
        }
        //Mac OSX
        else if (application.getOSName().match("Mac")) {
            application.executeProgram('open', vFilePath)
        }
        application.setStatusText('')
    } else {
         application.output('File: ' + vFilePath.getName() + ' does not exist!')
    }
}

Re: Show PDF in servoy webclient

PostPosted: Fri Nov 26, 2010 12:59 am
by Yeroc
If you're running SmartClient under Java 6+ you can simplify this further and have Java launch the default program for your particular filetype:

Code: Select all
function openFile(vFilePath)
{
    vFilePath =  plugins.file.convertToJSFile(vFilePath)
    if(vFilePath.exists()) {
        application.setStatusText('<html><b>Opening file: ' + vFilePath.getName() + ' Please wait....</b></html>')
        application.updateUI()
        var desktop = java.awt.Desktop.getDesktop();
        desktop.open(new java.io.File(vFilePath.getAbsolutePath()));

        application.setStatusText('')
    } else {
         application.output('File: ' + vFilePath.getName() + ' does not exist!')
    }
}

Re: Show PDF in servoy webclient

PostPosted: Fri Nov 26, 2010 1:06 am
by Harjo
Cool example! thanks

I see here, http://download.oracle.com/javase/6/doc ... sktop.html
that you even can do edit & print to native applications, directly from Java (from Java 1.6)
Do you know on which OS's this is working? could not find any info about that.

thanks again, for sharing!

Re: Show PDF in servoy webclient

PostPosted: Fri Nov 26, 2010 7:42 am
by ptalbot
I would be extra careful using this class directly from Servoy's JavaScript...

As you can see from the javadocs, most of these methods have lots of edgy conditions where they will spill various exceptions, so enclose this in a try/catch block at least, or use it in a plugin - I would recommend that ;)

Also if your client is running Java 5, this will not work and will spill a ClassNotFoundException.
But in Java 6, it should work on all platforms.

Also about the print() method, don't expect it to do a 'silent' print... this will open the target application and print with it (and leave it opened as well, which might not be wanted).