sys PDF Viewer

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

sys PDF Viewer

Postby alk » Thu May 12, 2022 7:18 pm


I would like to use this component, therefore I installed the corresponding Solution "sysPDFViewerExample"

Displaying website like '' as '' works fine, also PDFs located in the web

But I want to display a local PDF on my machine

Checking the dokumentation
it says "Load document using URL which is relative to the web applications's root context
In my case on the developer pc:
F:\Eigene Dateien\servoy_workspace_2022\svyPDFViewerExample\medias\test.pdf
'http://localhost:8080 medias/test.pdf' but, does not work
I got the tip (new Port) to use 8183

But I didn't work, also not working with the full path

'http://localhost:8183F:/Eigene Dateien/servoy_workspace_2022/svyPDFViewerExample/medias/test.pdf'

It must be a simple fault, but sorry I can't find it ...

Best Ralf
Posts: 50
Joined: Wed May 21, 2014 8:34 pm
Location: Berlin

Re: sys PDF Viewer

Postby robert.edelmann » Mon May 16, 2022 8:38 pm

Hi Ralf,

I don't think the Media-Files show up in the server like that.

You could create a temporary file and "copy" the contents

Code: Select all
var file = plugins.file.createTempFile('test','.pdf')
var url = plugins.file.getUrlForRemoteFile(file)
pdfForm.elements.pdf_Viewer.documentURL = url;

(i didn't test that, though, and I'm notoriously bad with files...)

We do it a bit differently, we have a form-variable on the pdf-form, which is bound to the dataProvider-property of the component. We use this method to display reports from Jasper Reports, since we get the data not as files but as bytes, so we avoid creating / handling / deleting temp-files on the server.
Code: Select all
reportBytes = plugins.jasperPluginRMI.runReport(dataSourceOrFs, report.path + "/" + report.fileName, '', plugins.jasperPluginRMI.OUTPUT_FORMAT.PDF, report.reportParameters, localeString);
var pdfForm = forms['pdf_viewer'];
if (pdfForm) {
    pdfForm.pdfData = reportBytes
    var mainWindow = application.getActiveWindow();
    scopes.svyCustomDialogs.showFormInDialog(pdfForm, 25, 25, mainWindow.getWidth() - 40, mainWindow.getHeight() - 100, 'Bericht', true, false)

The main downside is that we can't set the filename this way.
mit freundlichen Grüßen
Robert Stefan Edelmann
User avatar
Posts: 40
Joined: Wed Aug 14, 2013 6:12 pm

Re: sys PDF Viewer

Postby sbutler » Mon May 16, 2022 9:54 pm

Files that you want to work with locally (which I mean files that are local on the Servoy server, or your developer when testing), should really be located in (or moved to at runtime) plugins.file.getDefaultUploadLocation(). Which is something like C:\users\{username}\.servoy\uploads\{guid}\

Personally, I'd put them in a subfolder, like "templates" or something, so its at C:\users\{username}\.servoy\uploads\{guid\templates\test.pdf

That default upload location path can also be set at http://localhost:8080/servoy-admin/plugin-settings as servoy.FileServerService.defaultFolder setting.

Then, in your code you can do something like this:

Code: Select all
var file = plugins.file.convertToRemoteJSFile("/templates/test.pdf");
var url = plugins.file.getUrlForRemoteFile(file);
pdfForm.elements.pdf_Viewer.documentURL = url;

Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
Servoy Expert
Posts: 736
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH

Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 5 guests