Some test text!

Open a document

Contents

About opening a document
Learn more

To open a PDF document.

// open document from the filesystem
PDFDoc doc(filename);

// optionally read a PDF document from a stream 
MappedFile file(filename);
PDFDoc doc_stream(file);

// or pass-in a memory buffer
size_t file_sz = file.FileSize();
FilterReader file_reader(file);
unsigned char* mem = new unsigned char[file_sz];
file_reader.Read((unsigned char*)mem, file_sz);
PDFDoc doc(mem, file_sz);

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:

PDFDoc doc;

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:

PDFDoc doc("in.pdf");

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

MappedFile file(filename);
size_t file_sz = file.FileSize();
FilterReader file_reader(file);
unsigned char* mem = new unsigned char[file_sz];
file_reader.Read((unsigned char*)mem, file_sz);
PDFDoc doc(mem, file_sz);

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("in.pdf");
if (!doc.InitSecurityHandler())
{
  printf("Document authentication error...");
  return;
}

PDFTron SDK security API is explained in details in the Security section.

linkLearn more

Generating PDFs
An introduction to document creation.

Get the answers you need: Support

Contents

About opening a document
Learn more