Convert Figma logo to code with AI

pvginkel logoPdfiumViewer

PDF viewer based on Google's PDFium.

1,001
434
1,001
70

Top Related Projects

51,137

PDF Reader in JavaScript

iText for .NET is the .NET version of the iText library, formerly known as iTextSharp, which it replaces. iText represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high and low-level programming capabilities and the ability to create, edit and enha

Quick Overview

PdfiumViewer is a .NET library that provides a PDF viewer control based on the Pdfium PDF rendering library. It allows developers to embed a PDF viewer within their .NET applications, providing features such as zooming, panning, and annotations.

Pros

  • Cross-platform Compatibility: PdfiumViewer is compatible with multiple .NET platforms, including .NET Framework, .NET Core, and Xamarin, making it a versatile choice for a wide range of application development scenarios.
  • High-performance PDF Rendering: The library utilizes the Pdfium PDF rendering engine, which is known for its speed and accuracy in rendering PDF documents.
  • Extensive Feature Set: PdfiumViewer offers a comprehensive set of features, including support for annotations, text extraction, and password-protected PDFs.
  • Active Development and Community: The project is actively maintained, with regular updates and a responsive community of contributors.

Cons

  • Limited Documentation: The project's documentation could be more comprehensive, which may make it challenging for new users to get started.
  • Dependency on Pdfium: PdfiumViewer's performance and functionality are directly dependent on the Pdfium library, which may introduce potential compatibility issues or limitations.
  • Licensing Considerations: The Pdfium library is licensed under the Apache License, Version 2.0, which may have implications for certain commercial use cases.
  • Potential Performance Issues: While the Pdfium library is generally fast, large or complex PDF documents may still cause performance issues, especially on lower-end hardware.

Code Examples

Here are a few code examples demonstrating the usage of PdfiumViewer:

Rendering a PDF Document

using (var document = new PdfDocument("example.pdf"))
{
    using (var page = document.Pages[0])
    {
        var bitmap = page.Render(new Size(800, 600));
        // Display the bitmap in your application
    }
}

Extracting Text from a PDF Document

using (var document = new PdfDocument("example.pdf"))
{
    using (var page = document.Pages[0])
    {
        var text = page.ExtractText();
        // Process the extracted text
    }
}

Adding Annotations to a PDF Document

using (var document = new PdfDocument("example.pdf"))
{
    using (var page = document.Pages[0])
    {
        var annotation = new TextAnnotation(new RectangleF(100, 200, 300, 50), "This is an annotation.");
        page.Annotations.Add(annotation);
        document.Save("annotated_example.pdf");
    }
}

Handling Password-protected PDFs

using (var document = new PdfDocument("protected_example.pdf", "mypassword"))
{
    using (var page = document.Pages[0])
    {
        var bitmap = page.Render(new Size(800, 600));
        // Display the bitmap in your application
    }
}

Getting Started

To get started with PdfiumViewer, follow these steps:

  1. Install the PdfiumViewer NuGet package in your .NET project:

    Install-Package PdfiumViewer
    
  2. Import the necessary namespaces:

    using PdfiumViewer;
    
  3. Create a new PdfDocument instance and render a page:

    using (var document = new PdfDocument("example.pdf"))
    {
        using (var page = document.Pages[0])
        {
            var bitmap = page.Render(new Size(800, 600));
            // Display the bitmap in your application
        }
    }
    
  4. Explore the available features, such as text extraction, annotations, and password-protected PDFs, using the examples provided earlier.

  5. Customize the PDF viewer control by setting various properties and event handlers to fit your application's requirements.

Competitor Comparisons

51,137

PDF Reader in JavaScript

Pros of pdf.js

  • Cross-platform compatibility: Runs in any modern web browser
  • Lightweight and easy to integrate into web applications
  • Extensive documentation and active community support

Cons of pdf.js

  • Performance may be slower for large or complex PDFs
  • Limited support for advanced PDF features compared to native viewers
  • Requires JavaScript to be enabled in the browser

Code Comparison

PdfiumViewer (C#):

using (var document = PdfDocument.Load("document.pdf"))
{
    var page = document.Pages[0];
    var image = page.Render(300, 300, 96, 96, false);
    image.Save("output.png", ImageFormat.Png);
}

pdf.js (JavaScript):

pdfjsLib.getDocument('document.pdf').promise.then(function(pdf) {
  pdf.getPage(1).then(function(page) {
    var scale = 1.5;
    var viewport = page.getViewport({ scale: scale });
    var canvas = document.createElement('canvas');
    var context = canvas.getContext('2d');
    canvas.height = viewport.height;
    canvas.width = viewport.width;
    page.render({ canvasContext: context, viewport: viewport });
  });
});

iText for .NET is the .NET version of the iText library, formerly known as iTextSharp, which it replaces. iText represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high and low-level programming capabilities and the ability to create, edit and enha

Pros of itext-dotnet

  • More comprehensive PDF manipulation capabilities, including creation and editing
  • Actively maintained with regular updates and new features
  • Extensive documentation and community support

Cons of itext-dotnet

  • Commercial licensing required for many use cases
  • Steeper learning curve due to more complex API
  • Larger library size and potential performance overhead

Code Comparison

PdfiumViewer (rendering a PDF page):

using (var document = PdfDocument.Load("document.pdf"))
{
    var page = document.Render(0, 300, 300, false);
    pictureBox1.Image = page;
}

itext-dotnet (rendering a PDF page):

using (var reader = new PdfReader("document.pdf"))
using (var document = new PdfDocument(reader))
{
    var page = document.GetPage(1);
    var canvas = new Canvas(new PdfCanvas(page), new Rectangle(0, 0, 300, 300));
    canvas.Add(new Image(ImageDataFactory.Create("background.jpg")));
}

PdfiumViewer focuses on simple PDF rendering and viewing, while itext-dotnet offers more extensive PDF manipulation capabilities. PdfiumViewer is easier to use for basic viewing tasks, but itext-dotnet provides greater flexibility for complex PDF operations at the cost of a steeper learning curve and potential licensing considerations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

PdfiumViewer

Apache 2.0 License.

Download from NuGet.

Archived

I regret to announce I'm archiving this project. I haven't been able to spend any real time on this for a long time now, and must face the fact I'm not in a position to properly support this project.

I understand that even though I haven't been able to spend time, other developers have stepped in helping out answering issues, and archiving this project will make it more difficult finding help using PdfiumViewer. I'm sorry for this inconvenience.

Together with archiving this project, I will also be archiving the PdfiumBuild project. I'll make a number of successful builds available in the PdfiumBuild repository for anyone who needs them, but the build server will be shutdown as part of archiving these projects.

I've had a great time developing this project and helping you out using this project, and I'm sad I have to now close this down. I hope PdfiumViewer has been of value to you. The source code and NuGet packages won't be going anywhere, so keep using them if they're of value to you.

Introduction

PdfiumViewer is a PDF viewer based on the PDFium project.

PdfiumViewer provides a number of components to work with PDF files:

  • PdfDocument is the base class used to render PDF documents;

  • PdfRenderer is a WinForms control that can render a PdfDocument;

  • PdfiumViewer is a WinForms control that hosts a PdfRenderer control and adds a toolbar to save the PDF file or print it.

Compatibility

The PdfiumViewer library has been tested with Windows XP and Windows 8, and is fully compatible with both. However, the native PDFium libraries with V8 support do not support Windows XP. See below for instructions on how to reference the native libraries.

Using the library

The PdfiumViewer control requires native PDFium libraries. These are not included in the PdfiumViewer NuGet package. See the Installation instructions Wiki page for more information on how to add these.

Note on the PdfViewer control

The PdfiumViewer library primarily consists out of three components:

  • The PdfViewer control. This control provides a host for the PdfRenderer control and has a default toolbar with limited functionality;
  • The PdfRenderer control. This control implements the raw PDF renderer. This control displays a PDF document, provides zooming and scrolling functionality and exposes methods to perform more advanced actions;
  • The PdfDocument class provides access to the PDF document and wraps the Pdfium library.

The PdfViewer control should only be used when you have a very simple use case and where the buttons available on the toolbar provide enough functionality for you. This toolbar will not be extended with new buttons or with functionality to hide buttons. The reason for this is that the PdfViewer control is just meant to get you started. If you need more advanced functionality, you should create your own control with your own toolbar, e.g. by starting out with the PdfViewer control. Also, because people currently are already using the PdfViewer control, adding more functionality to this toolbar would be a breaking change. See issue #41 for more information.

Building PDFium

Instructions to build the PDFium library can be found on the Building PDFium wiki page. However, if you are just looking to use the PdfiumViewer component or looking for a compiled version of PDFium, these steps are not required. NuGet packages with precompiled PDFium libraries are made available for usage with PdfiumViewer. See the chapter on Using the library for more information.

Alternatively, the PdfiumBuild project is provided to automate building PDFium. This project contains scripts to build PdfiumViewer specific versions of the PDFium library. This project is configured on a build server to compile PDFium daily. Please refer to the PdfiumBuild project page for the location of the output of the build server. The PdfiumViewer specific libraries are located in the PdfiumViewer-... target directories.

Bugs

Bugs should be reported through github at http://github.com/pvginkel/PdfiumViewer/issues.

License

PdfiumViewer is licensed under the Apache 2.0 license. See the license details for how PDFium is licensed.