Showing the content of a pdf file

Hi everyone
I am building a visual windows application using openframeworks and C++.

The application is supposed to show the user the contents of some pdf files, one file at a time, and the user can navigate to the next/previous file.

The pdf files have only one page each, and there are totally somewhere between 400 and 500 pdf files, so the application should load each pdf from file only when it’s supposed to be shown to the user and then load the next one when the user moves to the next file.

The pdf files might change later at runtime by the client, so it is essential that the application loads them at runtime.

I have already done this with image files, but had no luck with pdf files yet.

Apparently openframeworks doesn’t have any utility for showing a pdf file or drawing it as an image, although it has some methods to write to a pdf file, like saving an image as a pdf.

I already saw this post suggesting to open the pdf file as a quick time movie file. I’ve tried it both on Windows and Linux with no luck. Apparently it only works in Mac.

Can anyone show me a possible solution?

Thanks

an option would be to convert the pdf files to some other format when the application starts or whenever there’s a new file, just check for pdf files for which there’s no png from time to time and convert them. in linux using convert it’s really easy to turn a pdf into a png or any other format, something like:

convert -density 96 -depth 8 -quality 85 a.pdf a.png

should work and you can just call it from inside the app using something like:

system("convert -density 96 -depth 8 -quality 85 a.pdf a.png");
1 Like

Thanks a lot Arturo
I’ll try that. :smile:

Another route could be using webview. Chrome can natively handle PDFs so I don’t see why it wouldn’t work. This is how I’ve played .swf / .flvs in openFrameworks on windows in the past.

I haven’t tried web views in a while but I remember I got one of the following in Visual Studio without much fuss :


If I recall correctly it essentially treats the webview as a texture so it’s easy to draw / scale and you can send all the navigation events you want.

1 Like

Another option might be to use cairo which is sporting a PDF renderer. A quick scan of ofxaddons.com found @bgstaal’s ofxCairo.

1 Like

Hi,
I wonder have you worked it out? When it comes to PDF conversion process, I have another question for you. I wonder have you ever tried to convert PDF to image files before? I am testing the related PDF to JPG converting, PDF to PNG converting, and PDF to BMP converting programs these days. Do you have experience about it? Any suggestion will be appreciated. Thanks in advance.

Best regards,
Salvatore