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

Hi,

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

Displaying website like 'www.spiegel.de' as 'http:www.spiegel.de' 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
therefore:
'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
alk
 
Posts: 61
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')
file.setBytes(plugins.http.getMediaData("media:///test.pdf"),true)
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
robert.edelmann
 
Posts: 91
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
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH

Re: sys PDF Viewer

Postby alk » Sun May 22, 2022 12:23 pm

Hallo Robert,
Hallo Scott,

thanks a lot.
I am used to work with the jasperplugin for datadriven pdf

But this case ist much more simple, the PDF is ready and fixed, I just want display the content in a window in my application
I thought the pdfviewer would be perfect for this case and it works
a) showing a URL (https://www.spiegel.de/)
b) showing a pdf located in the internet (http://www.alkenbrecher.com/assets/Sapp ... ersion.pdf)

but if the file is located on my developer machine it doesnt work / find the file,
WIKI says in developer use "http://localhost: 8183/reports/test.pdf" - but test.pdf is not displayed
my whole path on a windows computer: F:\Eigene Dateien\servoy_workspace_2022\svyPDFViewerExample\medias\test.pdf

Any idea?

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

Re: sys PDF Viewer

Postby robert.edelmann » Mon May 23, 2022 11:18 am

The files from "http://localhost: 8183/" are not in your workspace, this is only where your settings / source / webcomponents may or may not reside.

The web-root of your tomcat-server is the ROOT-folder in your Servoy-Developer, somewhere under application_server. On my machine it's "/Applications/Servoy_2021.12.0.app/Contents/application_server/server/webapps/ROOT", but your path will be diffrent on a windows-machine.
mit freundlichen Grüßen
Robert Stefan Edelmann
User avatar
robert.edelmann
 
Posts: 91
Joined: Wed Aug 14, 2013 6:12 pm


Return to Programming with Servoy

Who is online

Users browsing this forum: Bing [Bot] and 4 guests