16

Is there a FREE library which will allow me to open a pdf and show it on a winform project. I know I could open it in adobe reader or something but it always seems so bloated to me and I would be relying on it being installed. Is there a nice lightweight alternative where I could just include a dll in my project or similar avoiding external dependencies.

I don't need much functionality just view, change page zoom..

I have seen a few libraries but they seem to be about creating PDF's not viewing.

1

9 Answers 9

9

I'm not sure what you call a 'dependency' since you'll always have to rely on some external code to render the PDF unless you bundle the whole PDF rendering source inside your project.

There are some commercial renderers and very few free ones.

If you want to avoid dependencies that you can't bundle then maybe you could have a look at the source code for SumatraPDF, an OpenSource PDF viewer for windows that uses MuPDF.
There is also Poppler, a rendering engine that uses Xpdf as a rendering engine. All of these are great but they will require a fair amount of commitment to make make them work and interface with .Net.

Most other open source libraries are only used for creating and managing PDF pages and I don't know any that actually does rendering; it's such a hard problem to solve right.

You may still want to consider using GhostScript as an interpreter because rendering pages is a fairly simple process.
The drawback is that you will need to either re-package it to install it with your app, or make it a pre-requisite (or at least a part of your install process).
It's not a big challenge, and it's certainly easier than having to massage the other rendering engines into .Net.

Have a look at this SO question I answered today.
It contains some more information and a link to some working .Net code I posted on another forum a few months ago.

0
7

First you need to reference the Adobe Reader ActiveX Control

Adobe Acrobat Browser Control Type Library 1.0

%programfiles&\Common Files\Adobe\Acrobat\ActiveX\AcroPDF.dll

Then you just drag it into your Windows Form from the Toolbox.

And use some code like this to initialize the ActiveX Control.

private void InitializeAdobe(string filePath)
{
    try
    {
        this.axAcroPDF1.LoadFile(filePath);
        this.axAcroPDF1.src = filePath;
        this.axAcroPDF1.setShowToolbar(false);
        this.axAcroPDF1.setView("FitH");
        this.axAcroPDF1.setLayoutMode("SinglePage");
        this.axAcroPDF1.Show();
    }
    catch (Exception ex)
    {
        throw;
    }
}

Make sure when your Form closes that you dispose of the ActiveX Control

this.axAcroPDF1.Dispose();
this.axAcroPDF1 = null;

otherwise Acrobat might be left lying around.

2
  • Can you process text in PDF and then higlight it inside openned PDF(using library you described)?
    – Yoda
    Nov 11, 2014 at 23:51
  • 4
    What is the name of the control to drag after adding reference?
    – Yoda
    Nov 12, 2014 at 0:43
5

I would look into Foxit Reader as a lightweight alternative to Adobe Reader. It consists of a single .exe file that you can bundle with your application and thus shouldn't require any installation. According to their EULA this is allowed, as long as your application is not installed on mobile devices. All you would have to do is launch the reader as a new process, pointing to the appropriate pdf. Obviously the downside to this approach is it won't be integrated into your application's interface.

2

The ActiveX control installed with acrobat reader should work, either drop it in via the designer or use something like this.

This will require the relevant version of the reader is installed on the client but since you indicate that you could just launch that anyway this should not be a problem. reader

2
  • Yeah but as I said currently it's not an issue but I would prefer not to have the dependencies as things quickly change.
    – PeteT
    Feb 14, 2009 at 21:09
  • Agreed, this shouldn't be the solution since OP said "no dependencies".. Renaud's answer is much more complete.
    – Losbear
    Apr 12, 2019 at 18:08
2

Take a look at this. It requires quite a few libraries (including GhostScript), so it's not terribly light weight. But all dependencies included native reading of PDF. It's in VB--but could be translated if you need C#:

http://www.codeproject.com/Articles/37458/PDF-Viewer-Control-Without-Acrobat-Reader-Installe

0
0

There is a free PDF library. It is mainly editing the contents but it might help.

0

This is a guess.

The way browser render PDF inside it with a plug-in. I am not sure whether it requires the application to be installed.

You can use Foxit reader OR Sumatra PDF.
And, you can host the browser control on your winform.

0

Put a webBrowser control on your form. strPdfFile = "C:\SomeFile.pdf" webBrowser.Url = new Uri(strPdfFile);

This is worked for us until tried on a Win7-64bit system. Need to do some debugging now.

2
  • 1
    That webBrowser control would still need some kind of pdf reader plugin.
    – JohnSaps
    Jul 29, 2015 at 16:57
  • webbrowser still not enough,tough?
    – gumuruh
    Apr 22, 2020 at 3:57
0

You can use Spire.PDFViewer from Nuget. See here

1
  • This is not a free library
    – viraptor
    Nov 5, 2021 at 4:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.