Resolved Best Way To Display Pdf On Screen?

Dalski

Active member
Joined
Jun 3, 2020
Messages
40
Programming Experience
Beginner
Shockingly there is nowhere near as much info out there on this than what you'd think there would be. I need to display a pdf as an image on screen. Hopefully most of the time they will be clean vectors, however sometimes they will be rasterized.

PDFSharp seems like the open-source solution. For my purposes I'll be treating them as images. I do not want the Adobe Preview Window with tools. I just want to display as an image really; with single-pixel thick lines.

PDF Sharp does not give nowhere near enough info Main Page - PDFsharp and MigraDoc Wiki.

Another ten year old solution Using Adobe Reader in a WPF app but I think I'd rather PDF Sharp.

Anyone know what my best route is here? I cannot believe there is no decent youTube tutorials/ articles on this fundamental topic. Perhaps because it is so vital developers have not written decent articles on it?
 
Thanks Sheepings, you're completely right; lots of results there. But my concern is, is that how it's done; converting a pdf to an image, then using that?

Ideally I want single-line pixels as I'm using it for measuring.

Well I might look at ImageMagick now I think.
 
If you are using it for measuring, do you know what the pixel pitch of the target machines on which you will be displaying the images on are? You can have a 1600x1200 screen that is only 15" diagonal vs another 1600x1200 screen that is being displayed by a 60" projector.
 
Great point, thanks Skydiver. The user would have to draw a couple of lines; one for vertical scale, the other for horizontal. Store all measurements in an array/ database, and rescale them accordingly to linear algebra & matrix math I presume. I'll have to take a reference of the zoom; or something like that & all the measurements will be scaled accordingly.

I'm designing it based on 1920 x1080px.
 
I'm designing it based on 1920 x1080px
Hmm, unless I'm missing something obvious here? Why?

Why not get the users screen resolution and calculate off that instead?

Seems like a bad idea to assume everyone will use such a resolution. What about laptop users, tablet users, etc or do they not matter?

What OS's are you targeting?
 
Thanks Sheepings, yeah that'll be better. To be honest it's a tool for me only to enable me to do my job better. It's developed into an obsession. As you know my knowledge is very limited & this'll be the first app I've written in C#.
 
I used Ghostscript.Net for a good while, but seems it was discontinued in 2016, there were also other issues. Then in search of replacement I tried (Image) Magick.Net and was very displeased with processing speed, I think this is more aimed at image processing. Then I found Docnet.Core 2.1.2 which is extremely fast, it's a wrapper for Googles pdfium open-source PDF generation and rendering library that is used in Chrome browser.
 
Brilliant input John, many thanks for that. Well sir Docnet.Core 2.1.2 I'm looking at!

It'd be great to keep it as a pdf because on the documents where I am lucky to still have text (not rasterized) then I could really do with keeping this text to save the user having to re-key in this data.

EDIT - Is there any user manuals on Docnet.Core?
 
Last edited:
If you mean it's difficult, then at least for my use I didn't think so. Here's a short version of the example:
C#:
using (var docReader = DocLib.Instance.GetDocReader(@"D:\test.pdf", new PageDimensions(1080, 1920)))
using (var pageReader = docReader.GetPageReader(0)) // 0 is first page
{
    var rawBytes = pageReader.GetImage();
    var bmp = new Bitmap(pageReader.GetPageWidth(), pageReader.GetPageHeight(), PixelFormat.Format32bppArgb);
    AddBytes(bmp, rawBytes);
    pictureBoxPageView.Image = bmp;
}
AddBytes method can be copied from their example.
 
Thanks John, that's most helpful. Ideally it would be great if I could "stitch" pdfs together. By this I mean bringing another image to the screen & joining it to the already existing image on the screen, whilst being able to resize it.

The reason for this is that we receive blueprints of housing developments spread over several pages.
 
Back
Top Bottom