Skip to content

ANcpLua/CreatePdf.NET

Repository files navigation

codecov .NET 8 .NET 9 .NET 10 NuGet License Docker

CreatePdf.NET

A simple, .NET library for PDF creation with text and bitmap rendering, plus optional OCR functionality for text extraction.

Usage

using CreatePdf.NET;

await Pdf.Create(Dye.Black)
    .AddText("Hello World")
    .SaveAsync("text.pdf");

await Pdf.Create()
    .AddPixelText("Hello World")
    .SaveAsync("pixel.pdf");

await Pdf.Create()
    .AddText("Hello World!")
    .SaveAndOcrAsync("text-ocr-demo");

await Pdf.Create()
    .AddPixelText("Hello World!")
    .SaveAndOcrAsync("pixel-ocr-demo");

await Pdf.Create()
    .AddText("Hello World!", Dye.Blue, TextSize.Large)
    .AddLine()
    .SaveAndOpenAsync("opens-the-pdf.pdf");

await Pdf.Create(Dye.White)
    .AddPixelText("Hello World!", Dye.Red, Dye.Brown, PixelTextSize.Medium)
    .AddLines(5)
    .SaveAndShowDirectoryAsync("opens-the-directory.pdf");

Stream-based PDF Processing

// Basic OCR with default settings
await Pdf.Load(pdfStream).OcrAsync();

// Custom OCR settings for individual needs
await Pdf.Load(pdfStream).OcrAsync(new OcrOptions
{
    Dpi = 600,          
    PageSegmentationMode = 3
});

To enable OCR functionality

Platform Installation
macOS brew install tesseract
Windows Download Tesseract and Ghostscript
Linux sudo apt-get install ghostscript tesseract-ocr

Note: Only needed for OCR.

PDF generation works without it.

Installation

dotnet add package CreatePdf.NET --prerelease

Requirements

  • .NET 8.0, 9.0, or 10.0 SDK

License

This project is licensed under the MIT License.