PDFConvert 1.0.3

dotnet add package PDFConvert --version 1.0.3
                    
NuGet\Install-Package PDFConvert -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PDFConvert" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PDFConvert" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="PDFConvert" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PDFConvert --version 1.0.3
                    
#r "nuget: PDFConvert, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PDFConvert@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PDFConvert&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=PDFConvert&version=1.0.3
                    
Install as a Cake Tool

PDFConverter

🚀 PDFConvert.Engine is a high-performance .NET library that converts PDF documents into self-contained HTML pages or individual images by rasterizing each page with precision and efficiency.

🔧 What It Uses

  • PDFium → PDF rendering engine (opens and rasterizes PDF pages)
  • SkiaSharp → Cross-platform image encoding (WebP, PNG, JPEG)
  • WebMarkupMin → HTML minification for optimized output

✨ Features

🌐 HTML Conversion

  • Convert PDFs into single standalone HTML files
  • Each page rendered as an <img> element with data URIs
  • Responsive design with mobile viewport support
  • Lazy loading and async decoding for optimal browser performance
  • Built-in HTML minification (compact and production-ready)

🖼️ Image Extraction

  • Extract individual pages as separate image files
  • Batch processing with suggested file names
  • Support for WebP, PNG, and JPEG formats

⚙️ Rendering Options

  • DPI scaling → control sharpness and file size (default: 144 DPI)
  • Quality control (1–100) for WebP/JPEG compression
  • Grayscale mode for minimal file size and clean monochrome output
  • Anti-aliasing with LCD text rendering for crisp text

🚀 Usage Examples

Convert PDF to HTML

using PDFConvert.Engine;
using PDFConvert.Engine.Enums;

// Load PDF as bytes
byte[] pdfBytes = File.ReadAllBytes("document.pdf");

// Convert to self-contained HTML
string html = PDFConverter.PdfToHtmlRaster(
    pdfBytes,
    dpi: 144,                      // Resolution (higher = sharper, larger file)
    quality: 100,                  // Image quality (1-100)
    imageFormat: ImageFormat.webp, // webp (recommended) | png | jpeg
    grayscale: false               // Enable grayscale rendering
);

// Save the result
File.WriteAllText("output.html", html);

Extract PDF Pages as Images

// Extract all pages as individual images
List<ImageResult> images = PDFConverter.PdfToImages(
    pdfBytes,
    dpi: 300,                      // High resolution for print quality
    quality: 90,                   // Slight compression for smaller files
    imageFormat: ImageFormat.jpeg, // JPEG for photos, WebP for text
    grayscale: true,               // Grayscale for documents
    baseName: "my_document"        // File prefix (optional)
);

// Save each page
foreach (var image in images)
{
    File.WriteAllBytes(image.SuggestedFileName, image.Bytes);
    Console.WriteLine($"Saved: {image.SuggestedFileName} ({image.Mime})");
}

Advanced Configuration

// High-quality document conversion
string html = PDFConverter.PdfToHtmlRaster(
    pdfBytes,
    dpi: 200,                      // Higher DPI for detailed documents
    quality: 95,                   // Near-lossless quality
    imageFormat: ImageFormat.webp, // WebP lossless compression
    grayscale: false
);

// Compact grayscale output for text documents
string compactHtml = PDFConverter.PdfToHtmlRaster(
    pdfBytes,
    dpi: 120,                      // Lower DPI for smaller files
    quality: 80,                   // Moderate compression
    imageFormat: ImageFormat.jpeg, // JPEG for smaller file size
    grayscale: true                // Grayscale for text documents
);

📊 Image Format Guide

Format Best For Quality File Size Notes
WebP Text documents, mixed content Lossless Small-Medium Recommended for most use cases
PNG Graphics with transparency Lossless Large Quality parameter ignored
JPEG Photo-heavy documents Lossy Small Good compression, no transparency

🔧 API Reference

PdfToHtmlRaster

Converts a PDF to a self-contained HTML page with embedded images.

Parameters:

  • pdfBytes (byte[]) - Raw PDF file content
  • dpi (int) - Target DPI (default: 144)
  • quality (int) - Image quality 1-100 (default: 100)
  • imageFormat (ImageFormat) - Output format (default: WebP)
  • grayscale (bool) - Render in grayscale (default: false)

Returns: Minified HTML string with embedded page images

PdfToImages

Extracts all PDF pages as individual image files.

Parameters:

  • pdfBytes (byte[]) - Raw PDF file content
  • dpi (int) - Target DPI (default: 144)
  • quality (int) - Image quality 1-100 (default: 100)
  • imageFormat (ImageFormat) - Output format (default: WebP)
  • grayscale (bool) - Render in grayscale (default: false)
  • baseName (string?) - Base name for files (default: "doc")

Returns: List of ImageResult objects with bytes, MIME type, and suggested filename


⚡ Performance Tips

  • Use WebP for best compression with high quality
  • Lower DPI (96-144) for web display, higher DPI (200-300) for print
  • Enable grayscale for text documents to reduce file size by ~60%
  • Adjust quality based on content: 100 for text, 80-90 for mixed content

🛡️ Error Handling

The library throws specific exceptions for common issues:

  • ArgumentNullException - When PDF bytes are null
  • InvalidOperationException - When PDF cannot be opened (corrupted, password-protected, or invalid format)
try
{
    string html = PDFConverter.PdfToHtmlRaster(pdfBytes);
}
catch (InvalidOperationException ex)
{
    Console.WriteLine($"PDF processing failed: {ex.Message}");
    // Handle corrupted or password-protected PDFs
}

📋 Requirements

  • .NET 6.0+ (uses modern C# features and records)
  • PDFium native libraries (platform-specific)
  • SkiaSharp for cross-platform image processing
  • WebMarkupMin for HTML optimization

🎯 Use Cases

  • Document Viewers - Convert PDFs for web display
  • Report Generation - Embed PDFs in web applications
  • Archive Systems - Create searchable HTML versions
  • Mobile Apps - Lightweight PDF viewing
  • Image Extraction - Extract pages for further processing
  • Print Workflows - High-DPI image generation
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 257 9/3/2025
1.0.2 179 9/3/2025
1.0.1 204 9/2/2025
1.0.0 183 9/1/2025

Added New Method for Rendering the images only