Some test text!

PDFTron C/C++ SDK for Windowskeyboard_arrow_down

PDFTron C/C++ SDK for Windows

In this document
chevron_rightCreating a simple PDF-to-image application
chevron_rightCode
chevron_rightCommon Questions
chevron_rightNext Steps

linkCreating a simple PDF-to-image application

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.

  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. Verify that the platform target (Win32 or Win64) of the application matches the PDFNetC.dll architecture.
  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.
  2. 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

The entire code for this example is given below for easy 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;
}

linkCommon Questions

Where should I call the PDFNet.Initialize()?

A question regarding PDFNet.Initialize() and Terminate().

Error: error LNK2019: unresolved external symbol impTRN_PDFNetInitialize.

Solution: You probably have mixed up the 32bit and 64bit versions of PDFNetC. Make sure that the DLL architecture matches the project platform setting.

Error: The evaluation version encountered an error in your system configuration. Please contact customer support at: sup...@pdftron.com. No reg. write rights

Solution: See Questions in the Demo/Trial Period section.

Error: The application was unable to start correctly.

Solution: Same as above, but at runtime you have the wrong PDFNetC.dll being loaded.

linkNext Steps

Please see the deployment page for more details on deployments and languages supported.

The demo/trial page has more information on demo mode limitations and licensing details.