Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preview PDF in C#

Tags:

c#

.net

pdf

c#-3.0

I'm looking for .NET GUI component (different than PDFsharp) allowing preview PDF 1-page document.
Basically I need something similar to PictureBox where I can load bitmaps and show it.

It would be great if that component allows zooming and moving picture inside.
Freeware solutions preferred :)

like image 453
Maciej Avatar asked Mar 16 '10 13:03

Maciej


People also ask

How do you preview a PDF?

Open Acrobat or Acrobat Reader. On the Edit menu, choose Preferences. In the Preferences dialog box, choose General in the Categories list, and then select the Enable PDF thumbnail previews in Windows Explorer check box.

How can I read a PDF like a book on my computer?

Once you've downloaded your PDF and opened it in Reader do the following: Select View > Page Display > Two Page View (or Two Page Scrolling if you prefer). Select Show Cover Page in Two Page View.

Why is my PDF preview pane not working?

Here's what you need to check: Verify that Show preview handlers in preview pane checkbox is checked. Make sure the checkbox Always show icons, never thumbnails is unchecked. In the Open File Explorer to dropdown under the General tab, choose This PC instead of Quick Access.

How do I read PDF files?

Find the PDF you want to open in your Files and double click to open. Select Adobe Acrobat (or whichever reader you downloaded) from the list of available options. If no list appears or the page opens in another application, you can right-click the file and select Open With to choose your PDF reader. Click Open.


3 Answers

Another option is to use the WebBrowser control in your GUI. It's going to use the browser to render the PDF, but I'd do that route rather than mess around with the Adobe Reader ActiveX component.

If you don't want any type of PDF reader available on the client, you could also convert it to a graphic file through GhostScript and display it as a bitmap.

like image 168
bryanjonker Avatar answered Nov 14 '22 02:11

bryanjonker


you can use activex component that comes with Acrobat Reader.

How to render pdfs using C#

like image 21
Andrey Avatar answered Nov 14 '22 02:11

Andrey


Question is rather old, but proposed solutions have significant drawbacks:

  • WebBrowser control relies on the IE and that it can display PDF documents (this is true only if Adobe Reader is installed)
  • GhostScript is licensed under AGPL and it requires rather expensive license for usage in closed source/commercial projects.

Fortunately free alternative exists: poppler tools (based on xpdf codebase) which are licensed under GPL and may be used as console utility. From .NET code it may be executed with System.Diagnostics.Process.

To simplify poppler tools usage we've developed NReco.PdfRenderer .NET wrapper that embeds poppler windows binaries (they're extracted on first use) and provides simple API for rendering PDF pages to image:

var pdfToImg = new NReco.PdfRenderer.PdfToImageConverter();
Image firstPageImg = pdfToImg.GenerateImage( "test.pdf", 1);

Component is not free, but its pricing is very reasonable.

like image 29
Vitaliy Fedorchenko Avatar answered Nov 14 '22 03:11

Vitaliy Fedorchenko