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.
- 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.
Install via NuGet by adding a reference to the PdfForge package:
dotnet add package PdfForge
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}");
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");
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);
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");
-
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.
This project is licensed under the GPL-3.0 license.