PdfSharpCore.Extensions 0.1.2.4

dotnet add package PdfSharpCore.Extensions --version 0.1.2.4                
NuGet\Install-Package PdfSharpCore.Extensions -Version 0.1.2.4                
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="PdfSharpCore.Extensions" Version="0.1.2.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PdfSharpCore.Extensions --version 0.1.2.4                
#r "nuget: PdfSharpCore.Extensions, 0.1.2.4"                
#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.
// Install PdfSharpCore.Extensions as a Cake Addin
#addin nuget:?package=PdfSharpCore.Extensions&version=0.1.2.4

// Install PdfSharpCore.Extensions as a Cake Tool
#tool nuget:?package=PdfSharpCore.Extensions&version=0.1.2.4                

PDFSharp.Extensions

The following are extension methods for PDFSharp to support and simplify some common operations.

This project started due to a project requiring for images that where scanned into a PDF to be extracted to allow for portions of the embedded images to be permanently redacted. Most of the solutions and partial bits of code were incomplete or didn't cover my test cases and needs. Originally, I solve the problem using the iTextSharp library but the licensing model for that project prohibited me from continued use and development.

Licensed under the MIT license.


This fork includes some maintenance from:


Image Utilities

Extension methods are provided for extracting images from an entire document, individual pages or specific images. Currently only RGB encoded images (/DeviceRGB) are supported with either /DCTDecode or /FlatEncode encoding. /Indexed colorspaces are also supported for /FlatEncode images including 1bpp images (black & white).

All images are extracted as SixLabors.ImageSharp.Image objects which can then be saved or manipulated as necessary.

Example

string filename = @"My.Sample.pdf";
Console.WriteLine("Processing file: {0}", filename);
using (PdfDocument document = PdfReader.Open(filename, PdfDocumentOpenMode.Import)) {
  int pageIndex = 0;
  foreach (PdfPage page in document.Pages) {
    int imageIndex = 0;
    foreach(Image image in page.GetImages()) {
      Console.WriteLine("\r\nExtracting image {1} from page {0}", pageIndex + 1, imageIndex + 1);
      
      // Save the file images to disk in the current directory.
      image.Save(String.Format(@"{0:00000000}-{1:000}.png", pageIndex + 1, imageIndex + 1, Path.GetFileName(filename)), ImageFormat.Png);
      imageIndex++;
    }
    pageIndex++;
  }
}

Notes

If you find a PDF file that contains an encoded image, which is a /DeviceRGB colorspace, that doesn't extract correctly, please send submit a issue and attach the offending PDF file or send via email.

Please do not complain about PDF files that are unable to be processed because they are iref encoded. This is a limitation of the PDFSharp libraries and on the product roadmap for implementation.

Helpers

A helper class has been created for a PdfDictionary object that will allow you to quickly inspect to see if the dictionary is an image. A number of other helper extension methods have been created for PdfItem and other base classes for common inspection related tasks.

PdfDictionary item;
if (item.IsImage()) {
  Image image = item.ToImage();
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
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
0.1.2.4 3,549 12/26/2022