You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP

PdfForge

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

PdfForge

A .NET library for rendering PDF documents into PNG files or memory buffers on GNU/Linux. This library requires the following system packages to be installed: - libpoppler-glib-dev - libcairo2-dev - libglib2.0-dev (Package names may vary depending on the distribution.) Features: - High-quality PDF to PNG conversion with scaling support - Optimized for applications requiring PDF rasterization - Suitable for document processing and display purposes

2.1.2
Version published
Maintainers
1
Created

PdfForge

NuGet

PdfForge is a library for rendering PDF documents into PNG images. It supports both saving pages to files and converting pages into byte arrays, making it a flexible solution for applications that need to work with PDF files in raster format.

Features

  • Open PDF documents from a file.
  • Render PDF pages to PNG images.
  • Save pages as PNG files.
  • Get pages as byte arrays (PNG format).
  • Supports scaling when rendering pages.

Installation

Install via NuGet by adding a reference to the PdfForge package:

dotnet add package PdfForge

Usage

Opening Document

To work with a PDF document, create an instance of the PdfForgeDocument class and provide the file path:

using PdfForge;

var pdfDocument = new PdfForgeDocument("sample.pdf");
Console.WriteLine($"Total Pages: {pdfDocument.TotalPages}");

Saving a Page as a PNG File

You can save a specific PDF page as a PNG file by specifying the page number and output file path:

pdfDocument.SavePageToPngFile(1, "page1.png");

Getting a Page as a Byte Array

You can also retrieve a PDF page as a byte array (in PNG format), useful for handling images in memory:

byte[] pageBytes = pdfDocument.GetPageBytes(1);

Releasing Resources

It's important to release resources when the document is no longer needed. You can call Dispose manually or use using to automatically release resources:

pdfDocument.Dispose();

Or with using:

using var pdfDocument = new PdfForgeDocument("sample.pdf");

Requirements

  • GNU/Linux OS

  • .NET 8.0+

  • Following system packages to be installed:

    • libpoppler-glib-dev
    • libcairo2-dev
    • libglib2.0-dev

    Package names may vary depending on the distribution.

🚫 Windows and macOS are NOT supported due to dependencies on Linux-specific libraries (Poppler, Cairo, GLib).

❗ This library relies on native Poppler and Cairo libraries, which are available only on Linux.

License

This project is licensed under the GPL-3.0 license.

FAQs

Package last updated on 14 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts