Open PDF from Webclient

Forum to discuss the Web client version of Servoy.

Open PDF from Webclient

Postby maria » Wed Nov 17, 2010 6:17 am

Please help me out here :?
I'm trying to use application.showURL(path); to open a PDF document and passing it the path to a valid document in the filesystem but it does not open.
No error messages, nothing at all.
The path is "file:///C:/server/temp/WebReports/ZZ0WDNM7.PDF" or similar a local path for the client.
If I paste the same path in the browser it opens just fine (if the document is saved locally on client).
I understand that the document needs to be on the server though? Anyway, I tried opening it on both server and client and neither worked.
In smart client the code works just fine.
Please help.

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

Re: Open PDF from Webclient

Postby mboegem » Wed Nov 17, 2010 9:34 am

Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1750
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Open PDF from Webclient

Postby maria » Thu Nov 18, 2010 7:57 am



Thanks Marc.Thanks for the link, very helpful.
However I'm doing something wrong as my code is not working.
Here's what I do:
Code: Select all
   var path = getPath(); //the absolute path to the PDF, document physically exists on disk at that stage and can be opened in the file system
   
   var success = plugins.file.copyFile(path, fileName); //copy to server directory
   
   if(success) {
      
      var serverURL = application.getServerURL()
      application.showURL(serverURL + "/" + fileName);
   }   



The file is generated in another directory on server machine and I try to copy it to the server directory to enable openning it in the browser.
At the point where it should place a copy of the file in the server directory 'success' returns 'true' but the file is not there, therefore Apache complains "The requested resource (/ZZ0ZUVCP.PDF) is not available."

What's wrong with copying the file?

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

Re: Open PDF from Webclient

Postby Harjo » Thu Nov 18, 2010 12:04 pm

Maria,

in webclient you can just do: plugins.file.writefile('myfile.pdf', vBinaryData)

than the webclient does the rest for you, popup that file for you.

vBinaryData, can be data from a database blob or just data that you read from a file: vBinaryData = plugins.file.readFile..........

Hope this helps
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 martinh » Thu Nov 18, 2010 2:45 pm

Harjo wrote:in webclient you can just do: plugins.file.writefile('myfile.pdf', vBinaryData)

than the webclient does the rest for you, popup that file for you.


Harjo,

I'm afraid that is not working.
When I do what you wrote, the file is written to the User/Downloads directory.
But that popup is not appearing.

But I must say also that the Jasper Viewer when using a Jasper report, is not doing a popup as well. Also in this case the pdf is written into the User/Downloads directory.
See this issue: https://www.servoyforge.net/issues/177

Could there be a relation between those 2 cases?

Because whatever I try, I'm not getting my pdf file shown in a webclient (5.1.4)

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 Harjo » Thu Nov 18, 2010 4:24 pm

Than you have accepted (once) in your browser, to always download that file immediatly.
look into your browser settings under download settings.... (always ask for me.......)

or try different browsers, (IE, firefox, etc..)
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 Harjo » Thu Nov 18, 2010 4:27 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: Open PDF from Webclient

Postby martinh » Thu Nov 18, 2010 4:41 pm

Harjo,

That is correct.

I tried it with the Jasper Report output and now it asks if I want to save the file.
But, I dont want to save the file, I want this file automatically opened, and that is not an option (in FF)
In IE8 I see quickly a browser window opened and disappearing immediately.

But opening a file from the server (somewhere on the server, not under servoy server directory like application_server\server\webapps\ROOT) and showing the file as pdf on the webclient, is still not working.

I have the following coding:

Code: Select all
   var _server = plugins.it2be_tools.server()
   var _ext = 'pdf'      
   var _server_path
   var _slash = '\\'
   var _server_file_name = '\\somedir\\somesubdir\\myFile.pdf'
   
   _server_path = _server.getApplicationServerDir() + _slash + 'attachments' + _slash + _server_file_name;

   var _binary = _server.readFile(_server_path)
   if (! _binary)
      return;
   
   var _tmp_file = plugins.file.createTempFile('', '.' + _ext)
   if (! _tmp_file)
      return;
   
   plugins.file.writeFile(_tmp_file, _binary)
   
   //   I tried both shown lines, but none of them works
   application.showURL('file:///' + utils.stringReplace(_tmp_file, '\\', '/'), '_blank')   
   application.showURL('file:///' + _tmp_file, '_blank')   


Am I doing somewthing wrong here? I expect a temporary file created on the local machine and then show it in the browser.
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 » Thu Nov 18, 2010 8:38 pm

you are thinking wrong, a webclient DOES have access to somekind of folder on your server, but showURL does only have access in the webapss/root folder (and further)

Did you read my post above yours?
that's the only way the SHOW the pdf immediatly (you need somekind of acrobat installed on windows)

It would be really a security issue to really open files directly from the web!!
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 martinh » Fri Nov 19, 2010 1:37 pm

Harjo,

I solved part of the problem by moving the files that I want to open somewhere under webapps/root folder, so that I can use the showUrl() to show the file directly from the server into the client browser.

But I still don't understand, what you wrote before:

in webclient you can just do: plugins.file.writefile('myfile.pdf', vBinaryData)

than the webclient does the rest for you, popup that file for you.


because I don't see the webclient doing all the rest for me :cry:

In Servoy 5 the plugins.file.writeFile() method was changed so that it writes on the client (that is what I understood).
So that means that the following coding must work. I don't see any reason why this shouldn't work:

Code: Select all
/**
* @properties={typeid:35,uuid:"9E24DCA9-AE93-4B2C-AE1B-D2B4C56C0A80"}
*/
var _output = null;

/**
* @properties={typeid:35,uuid:"FF41BA01-09B6-47D4-9173-ADB5B58BACD4"}
*/
var _server_path = 'D:\\Servoy_51\\application_server\\server\\webapps\\ROOT\\attachments\\globis\\35\\7\\4\\2\\7425E933-B28A-4539-A650-749D857B5D1B.pdf';

/**
* @properties={typeid:24,uuid:"8AC21BAC-A82B-4900-9711-2F9E3C7E1F25"}
*/
function onShowDocument()
{
   var _server = plugins.it2be_tools.server()

   _output = 'Get server object\n';
   _output += 'Read binary\n';     
   var _binary = _server.readFile(_server_path)

   if (! _binary)
   {
   _output += '... Failed\n';    
      return;
   }
   
   _output += '... OK\n';   
   
   var _tmp_file = 'C:\\Temp\\myFile.pdf'
   var _tmp_file2 = 'myFile.pdf'
       
   var _ok = plugins.file.writeFile(_tmp_file, _binary)
   _output += 'Binary file written to ' + _tmp_file + '\n';
   if (! _ok)
   {
      _output += '... Failed\n';   
      return;
   }

   _output += '... OK\n';
   _output += '... Size = ' + _binary.length + '\n';
   
   _ok = plugins.file.writeFile(_tmp_file2, _binary)
   _output += 'Binary file written to ' + _tmp_file2 + '\n';
   if (! _ok)
   {
      _output += '... Failed\n';   
      return;
   }

   _output += '... OK\n';
   _output += '... Size = ' + _binary.length + '\n';
   
   _output += 'Show in browser: ' + 'file:///' + utils.stringReplace(_tmp_file, '\\', '/') + '\n'
   _ok = application.showURL('file:///' + utils.stringReplace(_tmp_file, '\\', '/'), '_blank')   
   if (! _ok)
   {
      _output += '... Failed\n';   
      return;
   }

   _output += '... OK\n';   
   
   _output += 'Show in browser: ' + 'file:///' + utils.stringReplace(_tmp_file2, '\\', '/') + '\n'
   _ok = application.showURL('file:///' + utils.stringReplace(_tmp_file2, '\\', '/'), '_blank')   
   if (! _ok)
   {
      _output += '... Failed\n';   
      return;
   }

   _output += '... OK\n';   
}


The output shows the following:

Code: Select all
Get server object
Read binary
... OK
Binary file written to C:\Temp\myFile.pdf
... OK
... Size = 467493
Binary file written to myFile.pdf
... OK
... Size = 467493
Show in browser: file:///C:/Temp/myFile.pdf
... OK
Show in browser: file:///myFile.pdf
... OK


And I don't find the myFile.pdf on my client PC (not in Downloads directory, not in C:\Temp)
And there is not a new browser window shown (not even with message 'file not found')
I checked also my server directories. Also on the server in the C:\Temp directory I don't find this file.

As far as I can see all this is correct Servoy javascript and I really don't understand why this isn't working.

FireFox, Safari (for windows) and Chrome show the same behavior
IE shows message about popup-window but no pdf file shown either. But there is a message about file not found (the file that is not in C:\Temp)
And there is not a single errormessage in the log on the adminpages.

I really don't see what is wrong here :( :( :(
This is Servoy version 5.1.4 -build 964
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 2:24 pm

It's pretty simple

everything a webclient does with a file is ON the server!
so if your logs says: c:\TEMP, that is ON the server, 100%

your webrowser does not have access to your local c:\temp (ofcourse firefox en IE does have a temp folder for there cache)

BUT
if you test this on your developer (webclient started from developer) THAN c:\temp is the the temp-folder on your local c-drive.
you are than running server and webclient on the same machine.

EDIT:
and to workaround that all stuff in the webclient, servoy now helps you with that using: plugins.file.writefile("test.pdf", myBinaryData)
and streams that file from the server to your local webbrowser.

depending on your browser settings, you get download popup or (like in chrome) it downloads it immediatly to your browser-download folder.
that's the way the web & browsers works!

hope this clears it more..
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 martinh » Fri Nov 19, 2010 2:34 pm

Harjo,

I agree that it worked like you describe, but that was in Servoy 4.x

The release notes of Servoy 5.1 mention the following: (https://wiki.servoy.com:8443/display/Serv51/Upgrade+Notes)

Behavior change

Using the writeFile function of the File plugin in the Web Client
Prior to 5.1, the syntax plugins.file.writeFile(null/String,....) would write the file serverside, in 5.1 and beyond it will trigger the streaming behavior to the browser as described in the Release Notes.


and also from this page: (https://wiki.servoy.com:8443/display/Serv51/newFeatureHighLights)

writeTXTFile, writeFile & writeXMLFile: When used in a Web Client and specifying null or a String for the file parameter, the file will be streamed to the browser. Depending on the browser settings, the browser will present the user with a File Open/Save dialog or will open the file directly in the appropriate application. When streaming the file to the browser, the file plugin will try to determine the type of file and set the content type accordingly, so the browser can recognize the type of file and open it with the appropriate application.


So it is not that clear and simple for me, because it doesn't work like described above!
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 2:45 pm

it is working, you said it yourself:

I'm afraid that is not working.
When I do what you wrote, the file is written to the User/Downloads directory.


that is exactly how it works.......
plugins.file.writefile does not OPEN the file for you, it streams it to you
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 martinh » Fri Nov 19, 2010 3:42 pm

I have made some progress. Part of the problem I've been able to fix, but it is very dirty.

As you could see in my sample, you've seen the following:

:
var _server = plugins.it2be_tools.server()
var _binary = _server.readFile(_server_path)
var _ok = plugins.file.writeFile(_tmp_file, _binary)

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

The dirty thing in this situation is, that the application.showURL() cancels all the statements that you see before.
So now it becomes clear to me that you must avoid to use application.showURL() in the webclient, unless you want to go to a certain page after logging off from Servoy.

Now I see in my downloads directory indeed the filename (when _tmp_file doesn't have a path). If _tmp_file == null, then I see a file.bin appearing.

But still 2 things that are not clear:

1) The application.showURL() should had created a new dialog. Why didn't it create a new browser window instance?
2) In your previous post you wrote "... webclient does the rest for you, popup that file for you.". This popup is not working. Why?
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 4:00 pm

martinh wrote:I have made some progress. Part of the problem I've been able to fix, but it is very dirty.

As you could see in my sample, you've seen the following:

:
var _server = plugins.it2be_tools.server()
var _binary = _server.readFile(_server_path)
var _ok = plugins.file.writeFile(_tmp_file, _binary)


indeed, in webclient, just stop here!!
_ok = application.showURL('file:///' + utils.stringReplace(_tmp_file, '\\', '/'), '_blank')
:

The dirty thing in this situation is, that the application.showURL() cancels all the statements that you see before.
So now it becomes clear to me that you must avoid to use application.showURL() in the webclient, unless you want to go to a certain page after logging off from Servoy.

Now I see in my downloads directory indeed the filename (when _tmp_file doesn't have a path). If _tmp_file == null, then I see a file.bin appearing.

But still 2 things that are not clear:

1) The application.showURL() should had created a new dialog. Why didn't it create a new browser window instance?
2) In your previous post you wrote "... webclient does the rest for you, popup that file for you.". This popup is not working. Why?


1. I don't know how browsers handle the file:/// object. I never use that ( I think, file:/// only works in a browser, if the file is allready local!)
2. that depends on your browser settings, for instance IE pops here popsup with a dialog, Do you want to open, or save this file. for ecample: Chrome directly downloads the file to his download folder.
Look in both browser, to your settings:
here you see mine of Firefox: (in Dutch)
Schermafbeelding 2010-11-19 om 14.55.29.png
You do not have the required permissions to view the files attached to this post.
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

Next

Return to Servoy Web Client

Who is online

Users browsing this forum: No registered users and 3 guests