Some test text!

keyboard_arrow_down

Get started

Getting startedStep-by-step guide
play_arrow

Language bindings

Java.NET CoreAdding a license key
keyboard_arrow_down

Parsing and extraction

keyboard_arrow_down

Digital signatures

Overview
keyboard_arrow_down

PDF Processing API

Step-by-step guidekeyboard_arrow_down

Quick start

In this document
chevron_rightDownloads
chevron_rightYour first application: step-by-step
chevron_rightCode

The PDFTron SDK is quite simple to get started with. Just three steps actually:

  • Download the SDK
  • Open up a sample that interests you.
  • Compile and run

That's it! Yes, really. You are ready with your first sample application using the PDFTron SDK. If you would like to dig a little deeper on your own, the entire samples collection is made available as part of the SDK, as well as online.

linkDownloads

An evaluation or commercial license key is required to run PDFTron. If you are evaluating the SDK and do not have a key, please obtain one, and then visit this page via the link included in the trial email. If your company has licensed PDFTron then you already received your key in an email from team@pdftron.com. See sign in for more details.

If you would like a step-by-step guide to start, please read on.

linkYour first application: step-by-step

The best way to get started is to dive right in. Let us start with a simple task - convert the first page of a PDF document to an image. In the example code we will touch upon a few basics - how to initialize PDFNet, how to open a PDF document, how to get to pages within a document. We will also touch upon some of the advanced features like PDFDraw, that are covered in detail in other samples.

  1. Extract the SDK to a local folder on your machine.
  2. Open your favourite editor and create a new cpp file - say pdf2image.cpp in the Samples directory.
  3. Include the following headers in your code file.
#include <iostream>
#include <PDF/PDFNet.h>
#include <PDF/PDFDoc.h>
#include <PDF/PDFDraw.h>
  1. Add using namespace statements.
using namespace pdftron;
using namespace PDF;
  1. Inside your main function, add the PDFNet::Initialize() call. This needs to be called before any other calls to PDFNet and should only be called once in your main() function.
PDFNet::Initialize();
  1. Load an existing PDFDoc and initialize the default security handler. To open password protected PDFs see the Encryption sample.
PDFDoc doc(pdf_filepath);
doc.InitSecurityHandler();
  1. Export PDF to image.
PDFDraw draw;
draw.Export(doc.GetPage(1), image_filepath);
  1. Wrap everything in try / catch block., and add PDFTron::common::Exception catch.
try
{
    PDFNet::Initialize();
    PDFDoc doc(pdf_filepath);
    doc.InitSecurityHandler();
    PDFDraw draw;
    draw.Export(doc.GetPage(1), image_filepath);
}
catch(pdftron::Common::Exception& ex)
{
    std::cout << ex.GetMessage() << std::endl;
}
  1. Create a folder named output and cd into it. The expected folder structure above output is as shown below.
PDFNetC
  |-Doc
  |-Headers
  |-Lib
  |-output (the output is placed here in this example)
  |-Resources
  |-Samples (the code file is placed here in this example)
  1. Compile everything using g++.
g++ ../Samples/pdf2image.cpp -I../Headers -L../Lib -lPDFNetC -lstdc++ -lpthread -lm -lc -Wl,-rpath,../Lib -Wl,-rpath$ORIGIN -o pdf2image
  1. Run the program, with the first command line argument as a PDF file, and the second as the name of the image file to be generated. For example, running ./pdf2image input.pdf output.png will result in the first page of input.pdf being converted to a PNG file named output.png.

linkCode

The entire code for the example is given below for quick reference.

#include <iostream>
#include <PDF/PDFNet.h>
#include <PDF/PDFDoc.h>
#include <PDF/PDFDraw.h>

using namespace pdftron;
using namespace PDF;

int main(int argc, char** argv)
{
    try
    {
        PDFNet::Initialize();

        UString pdf_filepath(argv[1]);
        UString image_filepath(argv[2]);

        PDFDoc doc(pdf_filepath);
        doc.InitSecurityHandler();

        PDFDraw draw;
        draw.Export(doc.GetPage(1), image_filepath);
    }
    catch(pdftron::Common::Exception& ex)
    {
        std::cout << ex.GetMessage() << std::endl;
    }
    return 0;
}