Some test text!

platform
search

Quick start

Contents

Step-by-step
Code Summary

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

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.

linkStep-by-step (Your first application)

We will use a simple task for this example - 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.

The steps below presume familiarity with the Visual Studio environment. You can use the language switcher at the top to choose the language that you prefer.

  1. Open Visual Studio and create a new Win32 Console Application.
  2. Add the PDFNetC\Headers folder to your 'Additional Include Directories'.
  3. Add the PDFNetC\Lib\PDFNetC.lib file to your 'Additional Dependencies'.
  4. Copy PDFNetC.dll to the output directory. If the output directory doesn't exist you may need to compile the project to generate it.
  5. You can verify that you have the appropriate version of PDFNet.dll by checking the path from which the reference was added - the path should have x86 for 32-bit and x64 for 64-bit.
  6. Add include header statements to beginning of CPP 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. Add Initialization call. This needs to be called before any other calls to PDFNet and should only be called once in your main() or OnAppStartup() functions.
PDFNet::Initialize();
  1. Load arguments into UString object, as this will handle the different possible character types possible with Windows C++ projects.
UString pdf_filepath(argv[1]);
UString image_filepath(argv[2]);
  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 PDFNetException 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. Run program, where the first command line argument is a PDF file, and the second is the name of the image. The PDFDraw function defaults to PNG as the export format. Though the format may be specified explicitly if needed, we will be using the default format for this example. Running app.exe input.pdf output.png will result in the first page of input.pdf being converted to a PNG file file named output.png.

linkCode Summary

#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;
}

When you are ready to add new features using our SDK, be sure to start by checking out our code samples.

Get the anwsers you need: Support

Contents

Step-by-step
Code Summary