I just finished working on this Plugin and figured I would post it freely for feedback…and I also have a question I would like some help on.
This Plugin is called pdf_viewer and uses the JPedal Library for viewing PDF documents. (address is http://www.jpedal.org , free for non-commercial use). There are 2 files. Put “jpedal.jar” inside of \Servoy\lib and put “pdf_viewer.jar” inside of \Servoy\plugins
It launches a window outside of servoy and has the following methods to control the PDF Viewer…
launchPDFViewer():“Initialize PDF Viewer and show empty form.”
selectFile(): “Show open file dialog for user to select a file. Returns path of file selected.”
openFile(fileName):“Open a given PDF file by fileName, C:\file.pdf”
goToPage(pageNumber):“Go to a page in the PDF Viewer by pageNumber”
setVisible(boolean)“Set visibility of PDF Viewer to show and hide”
closePDFFile():“Close a file, but not the entire PDF Viewer”
exit():“Close the entire PDF Viewer”
getPageCount():“Get number of pages in PDF File”
getFileName():“Get name of PDF File that is open”
getCurrentPage():“Get number of current page being viewed in PDF Viewer”
Onto my question…
This works by passing in the file name of a PDF document. However, if I have a PDF stored in a media field in Servoy, how could I pass that into this plugin?
if I have a PDF stored in a media field in Servoy, how could I pass that into this plugin?
You can create a temp file on your local HD and load it with the binary data from your media field. This temp file will be created in the user home directory and automatically deleted upon the client shut down.
(example windows: C:\Documents and Settings\myName\Local Settings\Temp )
var vTempFile = plugins.file.createTempFile(“temp”, “.pdf”)
if(mediaField)//check for data
{
plugins.file.writeFile(vTempFile, mediaField);
}
//do stuff with vTempFile…
Were you aware of the fact that a modified jpedal.jar is already included with Servoy as a bean which allows you to display pdf’s directly within Servoy?
I was not aware of this, but I still do not see this implemented as a bean in Servoy. I have Version 3.0a13_01-build 361.
I know that you can drop the jpedal.jar directly into the beans folder, and it works fine. However, there are not methods available to control the PDF Viewer. Its like it’s own island inside of servoy. I attempted putting a wrapper on it to add available methods to call from Servoy, but it wouldn’t work for me…something about it attempting to close the application. It would also not resize or move properly when using the Servoy scroll bar.
So, I decided to implement as a plugin so that it would show in an external window to Servoy, but I would still have full control from within Servoy.
I would be interested to see how you implemented jpedal as a bean. Did add anything to the jar, or did you just use the standard jar?
In my application, I am attempting to make a document management system. (i’m also working on using Morena ,www.gnome.sk with Servoy). So I would need to be able to do something like…
Open this PDF, Go to page X, and resize to fit.
Also, access to certain PDF’s would be controlled through servoy. So, some people can see some files, and others can see different files. Same with printing.
Make sure to check the pdf support package when you install servoy, it’s not installed by default. The jpedal we ship is enhanced so it exposes it’s funcitons in the bean. More info and sample in this thread