Ask Reuben
Viewing PDF
How can I view a PDF document inside my Genero application?
The immediate answer to how to view a PDF document from a Genero application is to put the PDF document on a Web Server somewhere and view it using the launchURL front-call.
CALL ui.Interface.frontCall("standard","launchURL",url,[])
As per the tip in the documentation this maybe simplified with use of the ui.Interface.filenameToUri() method to generate a url for a PDF on your application server.
A method that also works on the GDC is to use FGL_PUTFILE to put the PDF where the GDC can reference it, and then use the shellExec front-call to view the PDF document.
CALL ui.Interface.frontCall("standard","shellExec", filename,result)
The characteristic of both techniques is that they are using the default viewer to view the PDF document. So in the browser it will view the PDF the same as any other web page shows a PDF, and in the GDC case it is the equivalent of double-clicking on a PDF file in Windows Explorer to view the PDF, normally Adobe Reader. You get the functionality of that default viewer.
The question of how to view a PDF is normally asked by those who are looking to view the PDF document inside a GDC window. That is not in a browser window or not in an Adobe window, but in a window of the Genero application. There are some techniques you can do to achieve that but first I’d like you to consider this. The 1.32 version of GDC was approximately 1.9Mb to download. The 3.20 version of GDC is approximately 78 Mb to download. A good portion of that extra 76 Mb is tied up in the in-built web browser required for Web Components and Universal Rendering. To add functionality to GDC window to display PDF, and other popular file extensions such as Word, Excel etc would increase the size even more and add more upgrade complexity to the GDC. Now one day the Qt libraries we use to build the GDC might include a PDF viewer and we may decide to include it and the GDC size might jump again. We do keep an eye on this and this is captured as this issue https://4js.com/support/issue/?id=GDC-3088 . You never know, one day we might feel comfortable including a PDF viewer inside the GDC.
Now I mentioned there were some techniques you could use to view a PDF document inside a Genero window.
One such technique I have put up in our Github repository https://github.com/FourjsGenero/ex_embeddedpdfviewer. This technique uses Genero Report Writer and takes advantage of the fact it can take a PDF document as input to a report with the PDFBox. It effectively takes a PDF as input and outputs each page as an image using fgl_report_selectDevice(“Image”). You then display each image inside your Genero application using an IMAGE widget using some actions to navigate pages as different images. As the README notes this might be slow for large documents and you lose the ability to select and copy but this might not be important to you.
Another technique was illustrated by a customer Snorri Bergmann at our 2018 user conference and you can see his presentation on the right hand side here. That utilises a web component using a third party library pdf.js. to render a PDF document using web technologies. As it is a web component, it is rendering inside a Genero application window. You are dependent on the maintainers of the third party library keeping it up to date and having the functionality required to display all PDF documents.
If you are interested in how Genero Report Writer shows a PDF document when you select fgl_report_selectPreview(TRUE) and fgl_report_selectDevice(“PDF”) have a read of GREDIR/src/bin/gviewdoc.4gl and you will see it uses launchUrl or shellExec front-calls.
I would recommend you keep things simple and use launchUrl or shellExec and get the functionality with using the standard viewer but there are alternative techniques out there if you really insist.