Display a PDF in winforms
Solution 1
ITextSharp allows you to create and manipulate pdf's, but does not provide any rendering options like Bradley Smith said in a comment above
I did something similar a long time ago and what I ended up doing was using Ghostscript to generate a tiff image from my pdf and displaying that instead. Obviously that just displays an image so if you need to edit the pdf, this won't work for you.
Ghostscript is command line only so I think you have to run it something like this:
Process.Start(@"c:\gs\gs.exe",
String.Format("-o {0} -sDEVICE=tiffg4 -dFirstPage={1} -dLastPage={2} {3}", "tiffPages.tif", fromPage, toPage, "inputfile.pdf"));
Solution 2
You can easily display PDF in WebBrowser
control. Add a webBrowser control to your Winform. Add the following method to your form.
private void RenderPdf(string filePath)
{
if (!string.IsNullOrWhiteSpace(filePath))
{
webBrowser1.Navigate(@filePath);
}
}
Call this method by passing PDF file path,
RenderPdf(@"PDF path");
Solution 3
This question is a copy of this
The answer I found:
i think the easiest way is to use the Adobe PDF reader COM Component right click on your toolbox & select "Choose Items" Select the "COM Components" tab Select "Adobe PDF Reader" then click ok Drag & Drop the control on your form & modify the "src" Property to the PDF files you want to read i hope this helps
Solution 4
what about using a viewer control from any vendor? Found it on the first page in google: viewer control for windows forms
ddoor
Updated on June 04, 2022Comments
-
ddoor almost 2 years
I am trying to display a PDF in a winform using C# .net
I have included the iTextSharp Library, and successfully opened the PDF file, however I get a
byte[]
back from iTextViewPdfReader reader = new PdfReader(GetURI("test.pdf")); reader.getPageN(1); //returns byte array
I can't find much documentation on this library, and I was wondering how I would get the PDF on the actual form, be it in a picture box or a webview. How do I display the pages of the PDF?
EDIT:
I Don't want to open it in a third party reader
I don't want dependencies on adobe reader
I want to focus on a solution with iTextSharp or something similar, as I need to secure the PDF, encrypt it and eventually alter it.