Show PDF in servoy webclient

Using Servoy to administrate the content of your website? Discuss all webrelated Servoy topics on this forum!

Show PDF in servoy webclient

Postby Rene van Veen » Tue Jul 14, 2009 4:30 pm

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
Rene van Veen
 
Posts: 8
Joined: Fri Sep 19, 2008 1:55 pm
Location: Nieuwegein

Re: Show PDF in servoy webclient

Postby Westy » Thu Jul 16, 2009 11:20 pm

Nice.

<embed> tag is new in HTML 5.

Dean
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Re: Show PDF in servoy webclient

Postby Foobrother » Mon Jun 21, 2010 1:43 pm

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
Current configuration: Servoy 5.2.6 Build 1011, Java 6u24, PostgreSQL 8.3, Windows Server 2003

Servoy / Java Developer
http://www.assetguardian.com
User avatar
Foobrother
 
Posts: 530
Joined: Tue Jan 13, 2009 5:46 pm

Re: Show PDF in servoy webclient

Postby Harjo » Mon Jun 21, 2010 2:29 pm

Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Show PDF in servoy webclient

Postby ptalbot » Mon Jun 21, 2010 4:16 pm

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.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Show PDF in servoy webclient

Postby Foobrother » Mon Jun 21, 2010 4:31 pm

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

Thx
Current configuration: Servoy 5.2.6 Build 1011, Java 6u24, PostgreSQL 8.3, Windows Server 2003

Servoy / Java Developer
http://www.assetguardian.com
User avatar
Foobrother
 
Posts: 530
Joined: Tue Jan 13, 2009 5:46 pm

Re: Show PDF in servoy webclient

Postby nromeou » Thu Oct 14, 2010 2:25 pm

Hi everybody,

Has anybody tested this in SmartClient??

Also with Servoy 5.x??

Thanks for the help
Cheers
nromeou
 
Posts: 215
Joined: Fri Sep 18, 2009 8:38 pm
Location: Montevideo, Uruguay

Re: Show PDF in servoy webclient

Postby Harjo » Thu Oct 14, 2010 3:47 pm

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!')
    }
}
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Show PDF in servoy webclient

Postby Yeroc » Fri Nov 26, 2010 12:59 am

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!')
    }
}
Yeroc
 
Posts: 109
Joined: Tue Aug 12, 2008 1:12 am
Location: Calgary, AB, Canada

Re: Show PDF in servoy webclient

Postby Harjo » Fri Nov 26, 2010 1:06 am

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!
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Re: Show PDF in servoy webclient

Postby ptalbot » Fri Nov 26, 2010 7:42 am

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).
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC


Return to Web Development

Who is online

Users browsing this forum: No registered users and 10 guests