I am working on an eclipse based application wherein I need to preview pdf documents as part of a functionality. As of now clicking on preview button opens a prompt for saving the pdf but it does not directly open the document in the required window. Is there any way where I can add any arguments/Plugins in the XULRunner or the application's ini file so that the pdf can be opened in the window itself by default ? (I am using Red Hat Linux 6.5 (Santiago))
-
Does the XULRunner contain [PDF.js](https://mozilla.github.io/pdf.js/)? – howlger Feb 21 '19 at 10:08
-
No.. Should I add that ? – Knight of the Vale Feb 21 '19 at 11:34
-
As far as I know, Firefox uses PDF.js to display PDFs without the Acrobat Reader add-on. Please note that the development/maintenance of XULRunner is unfortunately discontinued. As an alternative to adding PDF.js to XULRunner, you could open an HTML page with PDF.js to display a PDF. – howlger Feb 21 '19 at 11:56
-
So is there no way to add PDF.js to XULRunner ? If no then could you please give me an example of how I could open an HTML page with PDF.js to display a PDF ? Most importantly how would I embed that in my application ? – Knight of the Vale Feb 21 '19 at 12:00
-
Probably there is a way to add PDF.js as an extension to XULRunner which I don't know. On the PDF.js web site there is a button [_Demo_](https://mozilla.github.io/pdf.js/web/viewer.html) which opens a HTML site that displays [this PDF](https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf) via PDF.js. – howlger Feb 21 '19 at 12:25
1 Answers
The following applies to Linux only. First of all, your SWT version must be < Eclipse 4.8, see https://www.eclipse.org/swt/faq.php#browserlinux
If your SWT meets this criterion, there's 2 options I know of:
Add plugin nppdf.so to your xulrunner install, needs Adobe Reader "acroread" executable with matching version on the PATH (maybe acroread version can be > nppdf version, not sure about that)
Use pdf.js: I got it to work using SWT from Eclipse 3.8.2, xulrunner 10.0.4esr and pdf.js < 2, e.g. 1.10.100.
UPDATE: this combination of versions has a problem with images in pdf-files, so I had to upgrade to: SWT 4.4 and xulrunner 24. pdf.js 1.10.100 still worked, 2.x would now also be usable, though.
In your xulrunner install, create file defaults/preferences/prefs.js (xulrunner.js also works), containing this line:
pref("security.fileuri.strict_origin_policy", false);
To view a pdf file, point your swt-embedded xul-runner to
file:///<pdf.js-dir>/web/viewer.html?file=<absolute-pdf-file-path>
This may apply:
However, we do ask if you plan to embed the viewer in your own site, that it not just be an unmodified version. Please re-skin it or build upon it.
https://mozilla.github.io/pdf.js/getting_started/#download
Sources:
- https://pinnau.blogspot.com/2016/03/scaleable-pdf-preview-first-page-in-swt.html
- https://www.eclipse.org/swt/faq.php#browserlinux
- http://ftp.mozilla.org/pub/xulrunner/releases/24.0/runtimes/
- https://developer.mozilla.org/en-US/docs/Archive/Mozilla/XULRunner/Getting_started_with_XULRunner
- https://github.com/mozilla/pdf.js/releases/download/v1.10.100/pdfjs-1.10.100-dist.zip
- https://stackoverflow.com/a/8014378/6329250
- https://mozilla.github.io/pdf.js/getting_started/#download

- 649
- 8
- 13