Some test text!

keyboard_arrow_down

Get started

keyboard_arrow_down

Xamarin.Forms

keyboard_arrow_down

Fundamentals

keyboard_arrow_down

Document Viewer (Android)

keyboard_arrow_down

Document Viewer (iOS)

keyboard_arrow_down

Document Viewer components

keyboard_arrow_down

Annotation and collaboration

keyboard_arrow_down

Advanced customization

keyboard_arrow_down

Conversion

keyboard_arrow_down

Search

keyboard_arrow_down

Advanced topics

Document savingDocument locking
keyboard_arrow_down

FAQ

System RequirementsPDFTron full vs. standardBuild split APKsLocalizationIcon cheat sheet
keyboard_arrow_down

PDF Processing API

What is PDFNet?Opening a documentSerializing (saving) a documentWorking with pagesWorking with Page ContentWorking with BookmarksWorking with Interactive Forms (AcroForms)PDF SecurityLow-level PDF APIError handling
Opening a documentkeyboard_arrow_down

Opening a document

The PDFDoc constructor creates a PDF document from scratch:

PDFDoc new_doc = new PDFDoc();

A newly-created document does not yet contain any pages. See the Working with Pages section for details on creating new pages and working with existing pages.

Using PDFNet, you can open a document from a serialized file, from a memory buffer, or from a Filter stream.

To open an existing PDF document from a file, specify its file path in the PDFDoc constructor:

PDFDoc mydoc = new PDFDoc("in.pdf");

Here's how to open an existing PDF document from a memory buffer:

FileStream stm = new FileStream("in.pdf", 
  FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(stm);
byte[] buffer = reader.ReadBytes(
  (int) reader.BaseStream.Length);
reader.Close();
PDFDoc mydoc = new PDFDoc(buffer);

It's also easy to open a PDF document from a MemoryFilter or a custom Filter such as HTTPFilter.

After creating a PDFDoc object, it's good practice to call InitSecurityHandler() on it. If the document is encrypted, calling the method will decrypt it. If the document is not encrypted, calling the method is harmless.

PDFDoc doc = new PDFDoc("in.pdf");
if (!doc.InitSecurityHandler())
{
  Console.WriteLine("Document authentication error...");
  return;
}

PDFNet security API is explained in details in the Security and PDF Security sections.