Some test text!

menu
search

Open a document

Only available with the Full API

To open a PDF document.

// open document from the filesystem or URL
const doc = await PDFNet.PDFDoc.createFromURL(filename);

// optionally read a PDF document from a stream
const file = await PDFNet.Filter.createURLFilter(filename);
const doc_stream = await PDFNet.PDFDoc.createFromFilter(file);

// or pass-in a memory buffer
const file_sz = await file.size();
const file_reader = await PDFNet.FilterReader.create(file);
const mem = await file_reader.read(file_sz);
const doc_mem = await PDFNet.PDFDoc.createFromBuffer(mem);

Read & write a PDF file from/to memory buffer
Full source code which illustrates how to read/write a PDF document from/to memory buffer. This is useful for applications that work with dynamic PDF documents that don't need to be saved/read from a disk.

linkAbout opening a document

The PDFDoc constructor creates a PDF document from scratch:

const doc = await PDFNet.PDFDoc.create();

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

Using PDFTron SDK, 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:

const doc = await PDFNet.PDFDoc.createFromURL("in.pdf");

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

const file = await PDFNet.Filter.createURLFilter(filename);
const file_sz = await file.size();
const file_reader = await PDFNet.FilterReader.create(file);
const mem = await file_reader.read(file_sz);
const doc_mem = await PDFNet.PDFDoc.createFromBuffer(mem);

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.

const doc = await PDFNet.PDFDoc.createFromURL("in.pdf");
if (!doc.initSecurityHandler())
{
  console.log("Document authentication error...");
  return;
}

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn more
close