PdfPig 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package PdfPig --version 0.0.1                
NuGet\Install-Package PdfPig -Version 0.0.1                
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="PdfPig" Version="0.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PdfPig --version 0.0.1                
#r "nuget: PdfPig, 0.0.1"                
#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 PdfPig as a Cake Addin
#addin nuget:?package=PdfPig&version=0.0.1

// Install PdfPig as a Cake Tool
#tool nuget:?package=PdfPig&version=0.0.1                

This project allows users to read text content from PDF files.

This project is based on PDFBox.

Usage

The PdfDocument class provides access to the contents of a document loaded either from file or passed in as bytes. To open from a file use the PdfDocument.Open static method:

using UglyToad.PdfPig;
using UglyToad.PdfPig.Content;

using (PdfDocument document = PdfDocument.Open(@"C:\my-file.pdf"))
{
    int pageCount = document.NumberOfPages;

    Page page = document.GetPage(1);

    decimal widthInPoints = page.Width;
    decimal heightInPoints = page.Height;

    string text = page.Text;
}

PdfDocument should only be used in a using statement since it implements IDisposable (unless the consumer disposes of it elsewhere).

You can pass a stream to PdfDocument.Open which will avoid loading the entire document into memory but may be slower for reading.

The consumer should wrap all access in a try catch block since it is highly likely to throw exceptions. As a fallback you can try running PDFBox using IKVM or using PDFsharp.

The document contains the version of the PDF specification it complies with, accessed by document.Version:

decimal version = document.Version;

Document Information

The PdfDocument provides access to the document metadata as DocumentInformation defined in the PDF file. These tend not to be provided therefore most of these entries will be null:

PdfDocument document = PdfDocument.Open(fileName);

// The name of the program used to convert this document to PDF.
string producer = document.Information.Producer;

// The title given to the document
string title = document.Information.Title;
// etc...

Page

The Page contains the page width and height in points as well as mapping to the PageSize enum:

PageSize size = Page.Size;

bool isA4 = size == PageSize.A4;

Page provides access to the text of the page:

string text = page.Text;

Letter

Due to the way a PDF is structured internally the page text may not be a readable representation of the text as it appears in the document. Since PDF is a presentation format, text can be drawn in any order, not necessarily reading order. This means spaces may be missing or words may be in unexpected positions in the text.

To help users resolve actual text order on the page, the Page file provides access to a list of the letters:

IReadOnlyList<Letter> letters = page.Letters;

These letters contain:

  • The text of the letter: letter.Value.
  • The location of the lower left of the letter: letter.Location.
  • The width of the letter: letter.Width.
  • The font size in unscaled relative text units (these sizes are internal to the PDF and do not correspond to sizes in pixels, points or other units): letter.FontSize.
  • The name of the font used to render the letter if available: letter.FontName.

Letter position is measured in PDF coordinates where the origin is the lower left corner of the page. Therefore an higher Y value means closer to the top of the page.

At this stage letter position is experimental and will change in future versions! Do not rely on letter positions remaining constant between different versions of this package.

Issues

Please do file an issue if you encounter a bug.

Status

Why is class or property X internal? With the exception of letter.Position internal properties and classes are not stable enough for the end user yet. If you want to access them feel free to use reflection but be aware they may change or disappear between versions.

The initial version of this package aims only to support reading text content from unencrypted PDF files. Due to the legal and dependency consequences of decrypting, handling encrypted documents is not in scope.

An encrypted document will throw a NotSupportedException.

We plan to eventually support writing PDFs as well as reading images, form objects and graphics from the PDF however these are future enhancements which do not feature in the first version.

Additionally most testing has taken place with Latin character sets. Due to the more complex way the PDF specification handles CJK (Chinese, Japanese and Korean) character sets these will probably not be handled correctly for now.

Please raise an issue (or preferably a pull request) if you're trying to read these documents however we may not get to it for a while depending on the volume of bugs.

Credit

This project wouldn't be possible without the work done by the PDFBox team and the Apache Foundation. Any bugs in the code are entirely my fault.

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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (47)

Showing the top 5 NuGet packages that depend on PdfPig:

Package Downloads
OrchardCore.Application.Cms.Core.Targets

Orchard Core CMS is a Web Content Management System (CMS) built on top of the Orchard Core Framework. Converts the application into a modular OrchardCore CMS application with TheAdmin theme but without any front-end Themes.

Microsoft.KernelMemory.Core

The package contains the the core logic and abstractions of Kernel Memory, not including extensions.

OrchardCore.Application.Cms.Targets

Orchard Core CMS is a Web Content Management System (CMS) built on top of the Orchard Core Framework. Converts the application into a modular OrchardCore CMS application with following themes. - TheAdmin Theme - SafeMode Theme - TheAgency Theme - TheBlog Theme - TheComingSoon Theme - TheTheme theme

Tabula

Extract tables from PDF files (port of tabula-java using PdfPig).

FileCurator

FileCurator is a simple manager for your files. It tries to give them a common interface to deal with files whether on your system or other locations.

GitHub repositories (13)

Showing the top 5 popular GitHub repositories that depend on PdfPig:

Repository Stars
OrchardCMS/OrchardCore
Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
dotnet/docfx
Static site generator for .NET API documentation.
SciSharp/BotSharp
AI Multi-Agent Framework in .NET
microsoft/kernel-memory
RAG architecture: index and query any data using LLM and natural language, track sources, show citations, asynchronous memory patterns.
paillave/Etl.Net
Mass processing data with a complete ETL for .net developers
Version Downloads Last updated
0.1.10-alpha-20241103-132ad 360 11/3/2024
0.1.10-alpha-20241031-d3bf6 179 10/31/2024
0.1.10-alpha-20241026-40af4 514 10/26/2024
0.1.10-alpha-20241019-e1060 523 10/19/2024
0.1.10-alpha-20241018-ea95a 125 10/18/2024
0.1.10-alpha-20241016-e903b 257 10/16/2024
0.1.10-alpha-20241013-f4054 198 10/13/2024
0.1.10-alpha-20241008-a2580 735 10/8/2024
0.1.10-alpha-20241007-c4672 293 10/7/2024
0.1.9 99,425 10/6/2024
0.1.9-alpha-20240930-eb9a1 2,856 9/30/2024
0.1.9-alpha-20240910-4845f 32,329 9/10/2024
0.1.9-alpha-20240909-09bdd 1,061 9/9/2024
0.1.9-alpha-20240904-cd2a8 1,311 9/4/2024
0.1.9-alpha-20240903-f4d14 715 9/3/2024
0.1.9-alpha-20240902-cf45d 592 9/2/2024
0.1.9-alpha-20240901-b824f 134 9/1/2024
0.1.9-alpha-20240821-b4649 5,354 8/21/2024
0.1.9-alpha-20240721-a99c0 20,168 7/21/2024
0.1.9-alpha-20240702-65c64 9,228 7/2/2024
0.1.9-alpha-20240628-bac00 6,784 6/28/2024
0.1.9-alpha-20240626-14e70 939 6/26/2024
0.1.9-alpha-20240625-dc933 597 6/25/2024
0.1.9-alpha-20240612-d2cae 4,351 6/12/2024
0.1.9-alpha-20240609-affc1 932 6/9/2024
0.1.9-alpha-20240601-65a18 2,232 6/1/2024
0.1.9-alpha-20240530-d7e43 757 5/30/2024
0.1.9-alpha-20240510-d86c2 9,553 5/10/2024
0.1.9-alpha-20240509-5a8e6 187 5/9/2024
0.1.9-alpha-20240508-995f2 272 5/8/2024
0.1.9-alpha-20240507-93779 255 5/7/2024
0.1.9-alpha-20240506-b6e03 188 5/6/2024
0.1.9-alpha-20240504-da44e 157 5/4/2024
0.1.9-alpha-20240429-7f42a 4,087 4/29/2024
0.1.9-alpha-20240419-1ef2e 6,879 4/19/2024
0.1.9-alpha-20240413-0f707 8,473 4/13/2024
0.1.9-alpha-20240406-2d6cb 3,467 4/6/2024
0.1.9-alpha-20240402-f6292 6,765 4/2/2024
0.1.9-alpha-20240324-e7896 4,682 3/24/2024
0.1.9-alpha-20240318-69e2b 11,495 3/18/2024
0.1.9-alpha-20240312-845e3 3,098 3/12/2024
0.1.9-alpha-20240307-ac027 1,768 3/7/2024
0.1.9-alpha-20240219-c2536 26,834 2/19/2024
0.1.9-alpha-20240217-f4e75 424 2/17/2024
0.1.9-alpha-20240216-f78b1 338 2/16/2024
0.1.9-alpha-20240215-3bdc9 1,899 2/15/2024
0.1.9-alpha-20240208-19734 4,597 2/8/2024
0.1.9-alpha-20240207-23445 1,369 2/7/2024
0.1.9-alpha-20240128-f886e 6,880 1/28/2024
0.1.9-alpha-20240121-04fc8 9,045 1/21/2024
0.1.9-alpha-20240117-096eb 5,006 1/17/2024
0.1.9-alpha-20240116-4e63e 831 1/16/2024
0.1.9-alpha-20240115-0da7b 868 1/15/2024
0.1.9-alpha-20240114-5953c 448 1/14/2024
0.1.9-alpha-20240112-83519 1,665 1/12/2024
0.1.9-alpha-20240111-88a14 823 1/11/2024
0.1.9-alpha-20240109-8cfaa 8,840 1/9/2024
0.1.9-alpha-20240108-18144 602 1/8/2024
0.1.9-alpha-20231119-4537e 16,891 11/19/2023
0.1.9-alpha-20231113-1bc0e 9,299 11/13/2023
0.1.9-alpha-20231029-17d50 5,393 10/29/2023
0.1.9-alpha-20231026-63096 5,545 10/26/2023
0.1.9-alpha-20231023-ba865 1,951 10/23/2023
0.1.9-alpha-20231019-c6e2d 4,303 10/19/2023
0.1.9-alpha-20230930-06ac8 7,271 9/30/2023
0.1.9-alpha-20230914-d59d2 6,442 9/14/2023
0.1.9-alpha-20230827-ee756 11,898 8/27/2023
0.1.9-alpha-20230806-4a480 8,922 8/6/2023
0.1.8 2,677,189 6/5/2023
0.1.8-alpha-20230605-7fe5f 994 6/5/2023
0.1.8-alpha-20230529-6daa2 6,615 5/29/2023
0.1.8-alpha-20230528-5126d 938 5/28/2023
0.1.8-alpha-20230524-20d3c 3,799 5/24/2023
0.1.8-alpha-20230523-11df5 950 5/23/2023
0.1.8-alpha-20230522-c3dd6 1,354 5/22/2023
0.1.8-alpha-20230423-3898f 37,995 4/23/2023
0.1.8-alpha-20230420-147b8 1,140 4/20/2023
0.1.8-alpha-20230419-2d72d 1,262 4/19/2023
0.1.8-alpha-20230417-cdc3d 1,351 4/17/2023
0.1.8-alpha-20230415-9eb79 1,080 4/15/2023
0.1.8-alpha-20230414-42e41 973 4/14/2023
0.1.8-alpha-20230413-46a04 1,072 4/13/2023
0.1.8-alpha-20230412-db058 1,711 4/12/2023
0.1.8-alpha-20230411-0e39b 1,095 4/11/2023
0.1.8-alpha-20230403-2e062 9,833 4/3/2023
0.1.8-alpha-20230331-bd4ee 18,815 3/31/2023
0.1.8-alpha-20230327-2daba 6,977 3/27/2023
0.1.8-alpha-20230326-58b33 1,101 3/26/2023
0.1.8-alpha-20230324-a3a9d 1,318 3/24/2023
0.1.8-alpha-20230323-a4861 1,117 3/23/2023
0.1.8-alpha-20230320-c024e 1,493 3/20/2023
0.1.8-alpha-20230318-a5c91 1,076 3/18/2023
0.1.8-alpha-20230219-999f9 2,719 2/19/2023
0.1.8-alpha-20230117-88aad 5,249 1/17/2023
0.1.8-alpha-20230109-65bc7 1,508 1/9/2023
0.1.7 770,660 12/13/2022
0.1.7-alpha-20221212-c8874 72,445 12/12/2022
0.1.7-alpha-20221210-2aed9 1,033 12/10/2022
0.1.7-alpha-20220814-2f9a9 6,277 8/14/2022
0.1.7-alpha-20220703-545d1 2,977 7/3/2022
0.1.7-alpha-20220622-fc71a 1,196 6/22/2022
0.1.7-alpha-20220618-f2188 1,053 6/18/2022
0.1.7-alpha-20220525-559f3 4,539 5/25/2022
0.1.7-alpha-20220511-ddab5 2,335 5/11/2022
0.1.7-alpha-20220503-4e490 1,881 5/3/2022
0.1.7-alpha-20220426-03692 1,183 4/26/2022
0.1.6 1,150,166 4/25/2022
0.1.6-alpha-20220425-2576c 1,125 4/25/2022
0.1.6-alpha-20220423-801a3 1,084 4/23/2022
0.1.6-alpha-20220415-cbd02 1,725 4/15/2022
0.1.6-alpha-20220411-09a62 1,216 4/11/2022
0.1.6-alpha-20220405-c2ecb 1,774 4/5/2022
0.1.6-alpha-20220404-6b085 1,070 4/4/2022
0.1.6-alpha-20220315-9c83e 3,883 3/15/2022
0.1.6-alpha-20220220-b0a5f 3,379 2/20/2022
0.1.6-alpha-20220116-e54cd 2,240 1/16/2022
0.1.6-alpha-20220113-5b66e 1,049 1/13/2022
0.1.6-alpha-20220112-b89c8 1,102 1/12/2022
0.1.6-alpha-20220111-41bfa 1,898 1/11/2022
0.1.5 969,014 9/17/2021
0.1.5-alpha002 5,076 5/9/2021
0.1.5-alpha001 25,745 2/28/2021
0.1.5-alpha-20211231-a57e5 2,340 12/31/2021
0.1.5-alpha-20211026-55244 1,091 10/26/2021
0.1.5-alpha-20210929-615e8 1,146 9/29/2021
0.1.5-alpha-20210918-4c36f 1,126 9/18/2021
0.1.5-alpha-20210828-e8f91 1,124 8/28/2021
0.1.5-alpha-20210827-e8f91 1,125 8/27/2021
0.1.5-alpha-20210817-b1f88 1,147 8/17/2021
0.1.4 620,240 11/29/2020
0.1.3 50,295 11/15/2020
0.1.3-alpha001 2,782 9/4/2020
0.1.2 247,691 7/4/2020
0.1.2-alpha003 1,336 6/20/2020
0.1.2-alpha002 3,603 5/10/2020
0.1.2-alpha001 1,374 4/25/2020
0.1.1 132,904 3/18/2020
0.1.1-alpha001 1,367 3/15/2020
0.1.0 201,837 1/13/2020
0.1.0-beta002 1,253 1/8/2020
0.1.0-beta001 1,255 1/6/2020
0.0.11 2,127 12/17/2019
0.0.10 1,778 12/9/2019
0.0.9 109,308 8/13/2019
0.0.7 1,719 8/3/2019
0.0.6 2,741 5/19/2019
0.0.5 17,604 12/30/2018
0.0.3 1,559 11/27/2018
0.0.1 10,647 2/26/2018
0.0.1-alpha-002 1,579 1/21/2018
0.0.1-alpha-001 1,570 1/10/2018