Open PDF from Webclient

Forum to discuss the Web client version of Servoy.

Re: Open PDF from Webclient

Postby martinh » Fri Nov 19, 2010 4:17 pm

Some more info:

In the following:

Code: Select all
var _ok = plugins.file.writeFile(_tmp_file, _binary)


the variable _tmp_file can only contain a filename and not a full path in the webclient.
So myFile.pdf is allowed, but C:\Temp\myFile.pdf isn't (it will try to save the file as C__Temp_myFile.pdf in my downloads directory)

And the line

Code: Select all
_ok = application.showURL('file:///' + utils.stringReplace(_tmp_file, '\\', '/'), '_blank')


will only create a new browser window when it is a http:// url, but not with a file:// url

And for me this explains also the problem that I have with the Jasper Report, where when running the report in webclient, that the option 'view' is not working, because it does exactly the same.
It streams the result of the Jasper Report to the browser and it tries to open the report in a new browser window using the file:/// url

So it looks like that when you want to show a Jasoer Report into the browser, that the binary report result (result from plugins.jasperPluginRMI.runReport()) that I have to do a writeFile myself so that the report is shown in a new window.

In my opinion it looks like there is a bug in the application.showURL(url, '_blank') where this doesn't work in all cases.
Can someone from Servoy confirm this?
Martin
------------------------------------------------
Servoy Developer
Version 5.2.10/5.2.13
Java version 1.6 update 31
Database SQL Server 2008 R2
martinh
 
Posts: 857
Joined: Wed May 09, 2007 5:34 pm
Location: Belgium

Re: Open PDF from Webclient

Postby Harjo » Fri Nov 19, 2010 5:13 pm

martinh wrote:Some more info:

In the following:

Code: Select all
var _ok = plugins.file.writeFile(_tmp_file, _binary)


the variable _tmp_file can only contain a filename and not a full path in the webclient.
So myFile.pdf is allowed, but C:\Temp\myFile.pdf isn't (it will try to save the file as C__Temp_myFile.pdf in my downloads directory)


EXACTLY! :-)
And the line

Code: Select all
_ok = application.showURL('file:///' + utils.stringReplace(_tmp_file, '\\', '/'), '_blank')


will only create a new browser window when it is a http:// url, but not with a file:// url

EXACTLY! :-)
And for me this explains also the problem that I have with the Jasper Report, where when running the report in webclient, that the option 'view' is not working, because it does exactly the same.
It streams the result of the Jasper Report to the browser and it tries to open the report in a new browser window using the file:/// url

So it looks like that when you want to show a Jasoer Report into the browser, that the binary report result (result from plugins.jasperPluginRMI.runReport()) that I have to do a writeFile myself so that the report is shown in a new window.

In my opinion it looks like there is a bug in the application.showURL(url, '_blank') where this doesn't work in all cases.
Can someone from Servoy confirm this?

I think this has everything todo, with your browser setting en specifically your popupblockers!
set those off and try again!
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: Open PDF from Webclient

Postby Andrei Costescu » Fri Nov 19, 2010 6:45 pm

Using file://... doesn't make sense in web-client. Because your solution is running in the browser from the app. server which is not local. When you try to show with showURL(...) it will try to open a new browser window on the client, not server, where the file://... that exists on the server does not make sense (it would try to reference actual files in the client file system, not on the server file system). This assumes that the file://... you are trying to show is really a file on the server.

If you are actually trying to open a file on the client, I doubt you know it's location on the client file system in javascript running on the server. Even if you do (hard-coded or user inputs it in client browser) you still won't be able to use it because the browser will see it as a dangerous attempt from some site to access a local file.

So the thing to do if needed in WC is either create the file on the server and serve it as a normal app. server link, or use Servoy defaults for doing this - media fields/plugin.file.write...
Andrei Costescu
Servoy
Andrei Costescu
 
Posts: 1018
Joined: Tue Jun 26, 2007 3:14 pm

Re: Open PDF from Webclient

Postby maria » Thu Nov 25, 2010 1:48 am

The following did the job for me.

There are two weird bits in it though that remain unclear to myself:

1. When I copy a file with plugins.file.copyFile(origPath, destinationPath); then I can't just make destinationPath = '/reports/reportName.pdf'. The file just does not appear in reports folder on server neither in 'developer' directory when running developer nor in application_server/server/webapps/root/reports when running a deployed solution. Only the absolute path to file works (and I get it by creating a dummy file in the server directory).

2. application.getServerURL(); returns 'localhost' instead of a valid server url. Need to use the server IP and concatenate it with the port number.

Code: Select all
   var path = generateReport(); //the function generates the pdf file on disk in a location external to the server and returns the path to the file
   
   var fileName = getFileName(); //this separates the file name from the path

   var tempFile = plugins.file.createFile("abrakadabra");
   var absServerPath = utils.stringReplace(tempFile.getAbsolutePath(), "abrakadabra", "");
   
   var copyFilePath = absServerPath + "\server\\webapps\\root\\webreports\\" + fileName;
   var success = plugins.file.copyFile(path, copyFilePath);
   
   var serverURL = application.getServerURL();
   application.showURL("http://" + plugins.it2be_tools.server().IP + utils.stringIndexReplace(serverURL, 1, utils.stringPosition(serverURL, ":", 1, 2), ":") + "/webreports/" + fileName);



Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: Open PDF from Webclient

Postby martinh » Fri Nov 26, 2010 11:40 am

Andrei Costescu wrote:Using file://... doesn't make sense in web-client. Because your solution is running in the browser from the app. server which is not local. When you try to show with showURL(...) it will try to open a new browser window on the client, not server, where the file://... that exists on the server does not make sense (it would try to reference actual files in the client file system, not on the server file system). This assumes that the file://... you are trying to show is really a file on the server.

If you are actually trying to open a file on the client, I doubt you know it's location on the client file system in javascript running on the server. Even if you do (hard-coded or user inputs it in client browser) you still won't be able to use it because the browser will see it as a dangerous attempt from some site to access a local file.

So the thing to do if needed in WC is either create the file on the server and serve it as a normal app. server link, or use Servoy defaults for doing this - media fields/plugin.file.write...


Andrei,

Could this also be the reason why the webclient doesn't show my Jasper Report in a new browser window.
Because it looks like the Jasper Report is downloaded to the client, but Servoy probably doesn't know where the report is placed, so it can't open a new window with a file:// prefix

So shouldn't the Jasper Report Plugin write the report result somewhere in a Temp directory within the application server\webapps\root directory (in case of a webclient), just like Maria showed in the above example, so that a new window can be opened?

Martin
Martin
------------------------------------------------
Servoy Developer
Version 5.2.10/5.2.13
Java version 1.6 update 31
Database SQL Server 2008 R2
martinh
 
Posts: 857
Joined: Wed May 09, 2007 5:34 pm
Location: Belgium

Re: Open PDF from Webclient

Postby jcompagner » Mon Nov 29, 2010 12:18 pm

jasper reports downloaded to the client? (client == webclient?)

That will not happen

If you want to stream a file to the browser/client then what harjo told you is correct

plugins.file.writefile('myfile.pdf', binaryPDFData,'application/pdf')

the 1st argument should be a String! not a File object on the server! Because if it is a file object it will try to save it on the server..
the 2d argument is the binary pdf data that you want to stream
the 3th argument is the mime type. For a pdf this shouldnt really be needed we will do that also for you, but if you know for sure you can set it yourself.

If you do that then normally that pdf should be opened by adobe reader inside or outside the browser. (if reader is installed ofcourse)

If it just directly saves it, then that is a setting you made in your browser
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Previous

Return to Servoy Web Client

Who is online

Users browsing this forum: No registered users and 6 guests

cron