Display PDF

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
dcbdbis
Experienced Solver
Experienced Solver
Posts: 80
Joined: Sun Nov 24, 2013 9:49 pm
Location: Aurora, Colorado

Display PDF

Post by dcbdbis »

Good Evening All,

Well, it looks like there is not a consensus nor an "orthodox" method on displaying PDF files. Things like wxPDFView are problematic - and fragile - requiring pdfium and other 3rd party utilities where stability and consistency is simply not guaranteed. Then we have wxPDFDocument which only generates PDF documents, not renders them to a wxImage or other format, etc.

My app is an Electrical Estimating App for a local contractor. They receive their design drawings in PDF form. In the C# version of the program I am porting to C++ and wxWidgets....I used a proprietary Windows specific library ($$) that internally converts the PDF into a raster image that I can put on a DC. So that the user can draw their conduit runs, and my software then calculates the length of the conduit/wire runs for estimating purposes.

I don't see anything to do this cleanly in wxWidgets under linux. This app is destined to eventually replace the C# version. The client wants it cross-platform - so the pdf "tooling" needs to be internal to my wxWidgets app. The client wants it to run on Linux and Windows.

I don't see a concise way to do this, at least at present. Please correct me if I am wrong.

At the moment, it seems that to maintain cross-platform compatibility, that the user is going to have to take responsibility to use some utility of their choosing, to convert the multi-page pdf file into individual images, so I can import them using conventional wxWidgets components.
Am I missing something?

Under linux, I have options such as poppler, imagemagick, etc. But no guarantees under Windows. No consistent API I can use.

So - I am sure others have done some sort of cross-platform utility, where PDF viewing was necessary. I ask those who have done it before, to please enlighten me on how it's done.

Thank you for any help and/or guidance you can provide....


Dave
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Display PDF

Post by doublemax »

As you already noticed, there is no obvious out-of-the-box working solution for this.

If i understand the ImageMagick licence correctly, it allows you to ship it with your application even for commercial purposes. Then call its command line utility from inside your app to convert the PDF to PNGs (or whatever) which you can load. This is probably the easiest way.

Now that we have proper browser support even under Windows with the new Edge/Chromium backend, other possibilities have opened up:

For just displaying a PDF, you could use the wxWebview component. But as you need to draw on top of it, this is not sufficient for your case.

Another option might be PDF.js. It should be possible to use PDF.js to render a PDF into a canvas, use canvas.toDataURL() to convert it into an image as base64 string, and return that string to the C++ application. https://gist.github.com/ichord/9808444
(100% speculation, i never tried that)
Use the source, Luke!
dcbdbis
Experienced Solver
Experienced Solver
Posts: 80
Joined: Sun Nov 24, 2013 9:49 pm
Location: Aurora, Colorado

Re: Display PDF

Post by dcbdbis »

@doublemax,

Kinda what I thought. Just wanted to validate it.

Thank you for confirming that I'm not missing something obvious. I had already looked at imagemagick - and that is probably the direction I'm going to go.

THANK YOU, for your reply.


Dave
Post Reply