Reading and modifying
editPdfDocument.Open reads an existing document: every member of PdfDocument then works on it as on a document you create. Pages can be read, drawn on, added and removed; the metadata, the outline and the attachments can be changed; and the document is saved again.
var document = PdfDocument.Open(file);
var pageCount = document.Pages.Count;
var text = document.Pages[0].ExtractText();What the reader supports
- Cross-reference tables and streams, hybrid files, object streams, incremental updates and linearized files.
- Every standard filter of the streams:
FlateDecodeandLZWDecode(with their predictors),ASCIIHexDecode,ASCII85Decode,RunLengthDecode,CCITTFaxDecode,JBIG2Decode, andDCTDecodeandJPXDecodethrough the codecs ofMeziantou.Framework.Imaging. - Encrypted documents of the standard security handler, with the user or the owner password.
- Damaged files: a file whose cross-reference information is wrong is repaired by scanning it, a stream whose length is wrong ends where its data ends, and the damaged data of a filter (
FlateDecode,ASCII85Decode,ASCIIHexDecode, a truncated row of a predictor) gives the bytes decoded before the damage.
The objects of a file are parsed when they are first used, not when the document is opened, and the document keeps the data of the file it was read from.
In this section
- Opening documents: files, streams and arrays, passwords, read options and repaired files.
- Extracting text: the text of a page, and search a document.
- Modifying documents: stamp the pages, add and remove pages, full and incremental saves.
- The object model: read and change the objects of a document directly.
- Errors and limits: the exceptions, and how to open the files of untrusted users.
- Managing pages: move, duplicate, remove and merge pages, page boxes, display coordinates, and stamp a page on others.
- Extracting images: the images of a page, where they are, and their pixels.
- Forms: create, read, fill and flatten the fields of an interactive form.