Some test text!

PDFTron SDK for .NET 4.0+keyboard_arrow_down

PDFTron SDK for .NET Framework 4.0+

In this document
chevron_rightPrerequisites
chevron_rightDownloads
chevron_rightCreating a simple PDF-to-image application
chevron_rightCode
chevron_rightSamples
chevron_rightCommon Questions

linkPrerequisites

End users of applications developed with PDFTron SDK for .Net 4.0 will need the Microsoft Visual C++ 2010 redistributable on their system (the files MSVCP100.DLL and MSVCR100.DLL). This is a standard component of Visual Studio, which is why it was not needed during development. End users may be instructed to install these directly using the package from Microsoft, or the DLLs can be included as part of the application install by including it in the same folder as your application. The appropriate (x86/x64) version of the VC++ 2010 runtime needs to be installed, based on the platform architecture that you are targeting.

What about AnyCPU? Isn't this is .NET we are talking about? Of course AnyCPU is supported - please see the deployment section for all the details.

The above components are available for download directly from the Microsoft website. The download links are given below.

linkDownloads

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 C# Console Application.
  2. Add a reference to PDFNet.dll.
  3. Verify that the platform target (x86 or x64) of the application matches the PDFNet.dll architecture.
  4. Add the following using statement to the beginning of the CS file.
using pdftron.PDF;
  1. Add the 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.
pdftron.PDFNet.Initialize();
  1. Load an existing PDFDoc and initialize the default security handler. To open password protected PDFs see the Encryption sample. Notice the using declaration; this is required to ensure that the PDFDoc object is released (including its handle on the actual file) when we are done. This is followed by exporting it to an image. (All the action in just three lines of code, yay!)
using (PDFDoc doc = new PDFDoc(args[0]))
{
    doc.InitSecurityHandler();
    PDFDraw draw = new PDFDraw();
    draw.Export(doc.GetPage(1), args[1]);
}
  1. Wrap everything in a try / catch block.
  2. Add PDFNetException catch to catch any exception thrown by the PDFNet library.
catch(pdftron.Common.PDFNetException ex)
{
    System.Console.WriteLine(ex.Message);
}
  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 the following command will result in the first page of input.pdf being converted to a PNG file file named output.png.
app.exe input.pdf output.png

linkCode

The full code for the above article is given below for easy reference.

using pdftron.PDF;

namespace pdftron.Samples.ExportImage
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // Expecting the following arguments:
                // args[0]: path to a PDF document.
                // args[1]: path to destination file (image).
                // Expected usage is: app.exe input.pdf output.jpg
                pdftron.PDFNet.Initialize();
                using (PDFDoc doc = new PDFDoc(args[0]))
                {
                    doc.InitSecurityHandler();
                    PDFDraw draw = new PDFDraw();
                    draw.Export(doc.GetPage(1), args[1]);
                }
            }
            catch(pdftron.Common.PDFNetException ex)
            {
                // Exceptions from the pdftron SDK.
                System.Console.WriteLine(ex.Message);
            }
            catch(System.Exception ex)
            {
                // Any other exceptions
                System.Console.WriteLine(ex.Message);
            }
        }
    }
}

linkSamples

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


linkCommon Questions

Where should I call PDFNet.Initialize()?

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

Error: warning MSB3270: There was a mismatch between the processor architecture of the project being built.

Solution: The architecture of the PDFNet dll and your project do not match. Either both the DLL, and project, should be x64, or x86. Don't mix and match. If using AnyCPU, it is not recommended for use with PDFNet as this can result in errors in some cases. For details, please see following link:

https://groups.google.com/forum/?fromgroups#!searchin/pdfnet-sdk/anycpu/pdfnet-sdk/MV8wBvAVCak/hrpjmcgUAQ8J

Error: System.BadImageFormatException: Could not load file or assembly PDFNet... An attempt was made to load a program with an incorrect format.

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

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

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