Show PDF in servoy webclient

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:

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:
Firefox (you need a google plugin to use it Google Code Archive - Long-term storage for Google Code Project Hosting.)
Safari

Kind Regards,

René van Veen
Ambitius

Nice.

tag is new in HTML 5.

Dean

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:

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:

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

I use Servoy 5.1.4 and IE 8

you need an url like: http://iptoyourserver:8080/blablabla

Westy:
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 instead.

Yes indeed! That was the problem.
I thought it would work as I was on Developer (same machine).

Thx

Hi everybody,

Has anybody tested this in SmartClient??

Also with Servoy 5.x??

Thanks for the help
Cheers

the tip here, was specially ment for webclient!!
to open a pdf (or any other file!) on smartclient you just can do this:

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!')
    }
}

If you’re running SmartClient under Java 6+ you can simplify this further and have Java launch the default program for your particular filetype:

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!')
    }
}

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!

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).