Getting started

keyboard_arrow_down

Basics

keyboard_arrow_down

Fundamentals

keyboard_arrow_down
Best practicesWebViewer HTML structureConfig filesUnderstanding ReaderControlMobile viewerThe streaming optionThe useDownloader optionUnderstanding coordinates

Components

keyboard_arrow_down

Annotations

keyboard_arrow_down

Advanced

keyboard_arrow_down

WebViewer UI (beta)

keyboard_arrow_down

PDFNetJS Full

keyboard_arrow_down

PDF Processing API

keyboard_arrow_down
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.