Resolved Best Way To Display Pdf On Screen?

Post number 2 has been selected as best answer.

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,788
Location
Chesapeake, VA
Programming Experience
10+
So basically, you want vector graphics for the drawing lines, and text blocks for the text. How will you determine if a text block is text that happened to close to a graphics entity vs. text which is actually a call out associated with a graphics entity? It's been decades since I've read the PDF specs -- before Adobe made it open. I don't recall a way to make that distinction back then. Maybe it is available now?

Anyway, the first question would be if the PDFs contain bitmaps, or vector graphics. If bitmaps, then you'll need to do some image processing (using OpenCV perhaps?) to get the vector lines out of the bitmaps. Obviously, if the PDF contains vectors already, you'll want to use those. Then you'll need to pull out the text as well. Some OCR (using Tesseract perhaps?) for bitmaps, or just get the text blocks if vectors.

Once you have those, as you said, it's just linear algebra to do scaling, rotations, and other transforms. The lines will be rendered how ever you want to render them: 1 pixel width lines, or fancy scrollwork if you wish.

RE: single pixel lines. You probably know this, but most modern renderers do not draw true single pixel lines. To make the lines look better on the display, specially when the lines are diagonal or curved, they use anti-aliasing which may use 2-5 pixels of varying shades to draw a single edge that crosses from one raster row/column to the next.
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
814
Location
Norway
Programming Experience
10+
To display Pdf you need either some kind of viewer control or convert to image. If need to manipulate the pdfs you need a different library.
 

Dalski

Active member
Joined
Jun 3, 2020
Messages
40
Programming Experience
Beginner
So basically, you want vector graphics for the drawing lines, and text blocks for the text. How will you determine if a text block is text that happened to close to a graphics entity vs. text which is actually a call out associated with a graphics entity? It's been decades since I've read the PDF specs -- before Adobe made it open. I don't recall a way to make that distinction back then. Maybe it is available now?
I've never displayed a pdf before, but the text like you say is a different entity/ element. I've only browsed the Adobe spec manual but text is most definitely distinguishable to graphical elements. Not sure by what you mean call-out; maybe you're referring to a comment. Nonetheless I'm not too concerned with this as the text will be used for batch processing to which I can easily program a flag/ notificiation that vital text is missing.

John the only manipulation needed is to scale and transform, would think most of them have this built-in; I'm pretty sure pdfSharp does.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,788
Location
Chesapeake, VA
Programming Experience
10+
Not sure by what you mean call-out; maybe you're referring to a comment.
Yes. But often it'll be text in a box, and that box has a line that points to or is attached to a graphic element.
 

Dalski

Active member
Joined
Jun 3, 2020
Messages
40
Programming Experience
Beginner
Spent most of the researching this further, I haven't been very clear in my opening post & apologies for the ambiguity. The main reason is I am learning; Using Adobe Reader in a WPF app is a great article & as I want to display a pdf whilst not loosing the text, & have access to the layers this would be great.

The article stipulates that a Windows Control Form is neccessary to display in WPF because it needs the Active-X control needs the WindowsHostForm element to work. My question is - as the article is 8 years old - is it still neccessary to insert a Windows Control Form. Could one not install a WPF User-Control or a more modern way to complete eradicate the Windows Form & have the app be entirely of WPF construction?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,788
Location
Chesapeake, VA
Programming Experience
10+
Yes, it is still needed. WPF does not have native ActiveX support, but WinForms does. Since WPF can host a WinForms control, that is how you can get an ActiveX control inside WPF.

If you don't want to do this, then you will have to provide all the infrastructure that is needed to support an ActiveX control inside WPF. It is really easy if the ActiveX control does not have to interact with the outer window, (only 3 or 4 interfaces to be implemented if I recall correctly), but it quickly gets more difficult when you need clipboard and menu interactions.
 
Last edited:
Top Bottom