VOOZH about

URL: https://docs.apryse.com/core/guides/get-started/cpp

⇱ C++ PDF Library for Windows, Linux, Mac | Apryse documentation


Product:

Section:

Product:

Release notes
Viewer
Basic operations
Learn more
Annotation
MS Office
Generate via template
Conversion
Smart Data Extraction
Augmenting LLMs with Smart Data Extraction
PDF/A
Accessibility
Forms
Create
Page manipulation
PDF Editing
OCR
Digital signature
Search
Comparison
Bookmark
Optimization
Layer (OCG)
Print
Redaction
Sanitization
Security
Portfolio
Low-level PDF API
Handwriting ICR
Changelogs

C++ PDF library integration

Welcome to Apryse. C++ for the Apryse SDK is cross-platform and supported on Windows and Linux. To get started, choose your preferred platform from the tabs below.

Windows C++ PDF library integration

This guide will help you run Apryse samples and integrate a free trial of the Apryse SDK into C++ applications on Windows. Your free trial includes unlimited trial usage and support from solution engineers.

Prerequisites

  • Visual Studio Make sure that the Desktop development with C++ workload and Windows 8.1 SDK are part of your installation. This guide will use Visual Studio 2017. The Troubleshooting section has information about other versions.
  • Apryse's C++ PDF library for Windows:

Download the SDK

download Windows 64-bit Apryse SDK

Run Apryse SDK in production

A commercial license key is required for use in a production environment. Please contact sales to purchase a commercial key or if you need any other license key assistance.

Keep your commercial license key confidential.

License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).

Initial setup

  1. Extract the folder from the .zip file.

This article uses PDFNET_BASE as the path into the folder that you extracted.

sh

1PDFNET_BASE = path/to/extraction/folder/PDFNetC(64)/
  1. Get your Apryse trial key.

License Key

Apryse collects some data regarding your usage of the SDK for product improvement.


The data that Apryse collects include:

  • The names and number of API calls
  • The number of pages in a document
  • The version of the SDK
  • The language of the SDK

For clarity, no other data is collected by the SDK and Apryse has no access to the contents of your documents.


If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.

Run the samples

Navigate to the location of extracted contents. Find and enter the Samples folder (PDFNET_BASE/Samples). Here you can find sample code for a large number of features supported by the Apryse SDK.

Find Samples_VC20XX.sln inside the Samples folder and open it with Visual Studio. Choose the appropriate solution based on your Visual Studio installation.

Run a specific sample

  1. Find the sample you want to run and set it as the Startup project.If you're running into issues, see the Troubleshooting section.
  2. Run the project.

Run all samples

  1. Make sure that the target type for the debugger is set to the right type for your machine and your Apryse SDK Download. Click on Local Windows Debugger to run all the samples.

If you prefer using command line to compile and run code, have a look at the Advanced section.

Integrate into your application

This section will help you build the "Apryse Hello World" application. It is easy to integrate the rest of Apryse SDK if you are able to open, save and close a PDFDoc.

Before writing the application, some dependencies needed to be with Visual Studio.

  1. Create a new C++ Console Project for Windows called myapp.
  2. Add PDFNET_BASE\Lib\PDFNetC.lib to the project's Additional Dependencies in the Linker Input settings.
  3. Add PDFNET_BASE\Headers to the project's Additional Include Directories in the C/C++ General Settings.
  4. Copy the PDFNET_BASE\Lib\PDFNetC.dll file to the project's output directory. Verify that the right version of PDFNetC.dll was added from the path used to add the reference.

The Troubleshooting section below has more detailed instructions for newcomers to Visual Studio.

The Code

Replace the contents of myapp.cpp with:

sh

1``` cpp
2
3#include <iostream>
4
5// Important for PDF related manipulations
6#include <PDF/PDFNet.h>
7#include <PDF/PDFDoc.h>
8
9// Important for document filesystem interaction and more
10#include <SDF/ObjSet.h>
11
12using namespace pdftron;
13using namespace PDF;
14using namespace SDF;
15
16
17int main()
18{
19 try
20 {
21 // This is required before any Apryse related
22 // classes and methods can be properly used
23 PDFNet::Initialize("YOUR_APRYSE_LICENSE_KEY");
24
25 PDFDoc doc;
26
27 // Create a new page and push it into
28 // the page sequence of the document.
29 Page page = doc.PageCreate();
30 doc.PagePushBack(page);
31
32 // Save the document as a linearized PDF which is the most
33 // popular and effective fast viewing format
34 doc.Save("linearized_output.pdf", SDFDoc::e_linearized);
35 }
36 catch (pdftron::Common::Exception& ex)
37 {
38 std::cout << ex.GetMessage() << std::endl;
39 }
40 return 0;
41}
42```

You can use the Local Windows Debugger button to build the solution and run the main function.

Once the code has been run, you can find a new document called linearized_output.pdf in the output directory of your project.

You can learn about and add more features by reading our guides, samples and API.

Advanced

Run samples using batch files and command prompt

1. Navigate into the folder for any sample that you like (PDFNET_BASE/Samples/X).

2. Create a new file inside the CPP folder called RunTest.bat. Paste the following code in it (replace X with the name of the Test folder):Save the file.

C++

1@echo off
2setlocal
3REM Replace X with the name of the Test folder, Ex. FDFTest
4set TEST_NAME=X
5if not exist PDFNetC.dll copy "%cd%\..\..\..\Lib\PDFNetC.dll" PDFNetC.dll
6cl /EHsc /I"../../../Headers" ../../../Lib/PDFNetC.lib %TEST_NAME%.cpp
7%TEST_NAME%.exe
8endlocal
9PAUSE

3. Open the Windows Start Menu and in Apps, scroll down and find the Visual Studio 2019 folder (not application). Expand it and click on Developer Command Prompt for Visual Studio 2017. Navigate to the test folder on your system.

4. Use the following to compile, build and run the test:RunTest.bat

Troubleshooting

Older versions of Visual Studio
Find out more about the Visual Studio versions we support.

Trouble setting dependencies
Set dependencies for the Apryse SDK in a startup project with Visual Studio.

Linux C++ PDF library integration

This guide will help you run Apryse samples and integrate a free trial of the Apryse SDK into C++ applications on Linux. Your free trial includes unlimited trial usage and support from solution engineers.

Prerequisites

  • GCC ≥ 4.2.1 (32-bit, 64-bit) or GCC ≥ 8 (64-bit ARM)
  • Apryse SDK for Linux:

Download the SDK

Run Apryse SDK in production

A commercial license key is required for use in a production environment. Please contact sales to purchase a commercial key or if you need any other license key assistance.

Keep your commercial license key confidential.

License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).

Initial setup

  1. Download the Apryse SDK.
  2. Extract via tar xvzf PDFNetC64.tar.gz or tar xvzf PDFNetCArm64.tar.gz or tar xvzf PDFNetCAlpine64.tar.gz or tar xvzf PDFNetC.tar.gz.
  3. Get your Apryse trial key.

License Key

Apryse collects some data regarding your usage of the SDK for product improvement.


The data that Apryse collects include:

  • The names and number of API calls
  • The number of pages in a document
  • The version of the SDK
  • The language of the SDK

For clarity, no other data is collected by the SDK and Apryse has no access to the contents of your documents.


If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.

Run the samples

Run a specific sample

  1. Navigate to the CPP folder in the sample you want to run and make the project by calling make. Then run the test by executing

sh

1./TEST_NAME

For example to run AddImageTest, navigate to /Samples/AddImageTest/CPP and execute ./AddImageTest.

Run all samples

  1. Navigate to /Samples and execute

sh

1./runall.sh

The tests will run one by one.

Output files will be in /Samples/TestFiles/Output

Integrate into your application

This section will show you how to use our SDK to create a simple Apryse "Hello World!" application. It will create a document with one blank page and save it as a linearized PDF in its running directory.

  1. Navigate to the /Samples directory and create a new directory called myApp if it does not exist already. This guide will assume your project is named myApp. Enter your myApp directory and create a CPP directory for organization. Then create a myApp.cpp file in the CPP directory.
  2. Open myApp.cpp with your favorite text editor and paste this inside:

C++

1#include <iostream>
2#include <PDF/PDFNet.h>
3#include <PDF/PDFDoc.h>
4#include <SDF/ObjSet.h>
5
6using namespace pdftron;
7using namespace PDF;
8using namespace SDF;
9
10int main(int argc, char** argv)
11{
12 try
13 {
14 PDFNet::Initialize("YOUR_APRYSE_LICENSE_KEY"); // PDFNet must be initialized before accessing any Apryse API. This line should only be called once in your main function.
15 PDFDoc doc;
16 Page page = doc.PageCreate(); // Start a new page
17 doc.PagePushBack(page); // Add the page to the document
18 doc.Save("output.pdf", SDFDoc::e_linearized); // Save the document as a linearized PDF
19 std::cout << "Hello World!" << std::endl;
20 }
21 catch(pdftron::Common::Exception& ex)
22 {
23 std::cout << ex << std::endl;
24 }
25 return 0;
26}
  1. Build the project using this line:

sh

1g++ myApp.cpp -I../../../Headers -L../../../Lib -lPDFNetC -lstdc++ -lpthread -lm -lc -Wl,-rpath,../../../Lib -Wl,-rpath$ORIGIN -o myApp
  1. Run the application via ./myApp. The output should read:

sh

1PDFNet is running in demo mode.
2Permission: write
3Hello World!

Check the output.pdf that the program output in the same directory. It should be a PDF with one blank page.

C++ & macOS PDF library integration

This guide will help you run Apryse samples and integrate a free trial of the Apryse SDK into C++ applications on macOS. Your free trial includes unlimited trial usage and support from solution engineers.

Prerequisites

  • GCC ≥ 4.2.1
  • Apryse's C++ PDF library for macOS:

Download the SDK

Run Apryse SDK in production

A commercial license key is required for use in a production environment. Please contact sales to purchase a commercial key or if you need any other license key assistance.

Keep your commercial license key confidential.

License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).

Initial setup

  1. Download the Apryse SDK. (above)
  2. Extract the downloaded zip file and navigate to it.
  3. Get your Apryse trial key.

License Key

Apryse collects some data regarding your usage of the SDK for product improvement.


The data that Apryse collects include:

  • The names and number of API calls
  • The number of pages in a document
  • The version of the SDK
  • The language of the SDK

For clarity, no other data is collected by the SDK and Apryse has no access to the contents of your documents.


If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.

Run the samples

Run a specific sample

  1. Navigate to the CPP folder in the sample you want to run and make the project by calling make. Then run the test by executing

sh

1./TEST_NAME

For example to run AddImageTest, navigate to /Samples/AddImageTest/CPP and execute ./AddImageTest.

Run all samples

  1. Navigate to /Samples and execute

sh

1./runall.sh

The tests will run one by one.

Output files will be in /Samples/TestFiles/Output

Integrate into your application

This section will show you how to use our SDK to create a simple Apryse "Hello World!" application. It will create a document with one blank page and save it as a linearized PDF in its running directory.

  1. Navigate to the /Samples directory and create a new directory called myApp if it does not exist already. This guide will assume your project is named myApp. Enter your myApp directory and create a CPP directory for organization. Then create a myApp.cpp file in the CPP directory.
  2. Open myApp.cpp with your favorite text editor and paste this inside:

C++

1#include <iostream>
2#include <PDF/PDFNet.h>
3#include <PDF/PDFDoc.h>
4#include <SDF/ObjSet.h>
5
6using namespace pdftron;
7using namespace PDF;
8using namespace SDF;
9
10int main(int argc, char** argv)
11{
12 try
13 {
14 PDFNet::Initialize("YOUR_APRYSE_LICENSE_KEY"); // PDFNet must be initialized before accessing any Apryse API. This line should only be called once in your main function.
15 PDFDoc doc;
16 Page page = doc.PageCreate(); // Start a new page
17 doc.PagePushBack(page); // Add the page to the document
18 doc.Save("output.pdf", SDFDoc::e_linearized); // Save the document as a linearized PDF
19 std::cout << "Hello World!" << std::endl;
20 }
21 catch(pdftron::Common::Exception& ex)
22 {
23 std::cout << ex << std::endl;
24 }
25 return 0;
26}
  1. Build the project using this line:

sh

1g++ myApp.cpp -I../../../Headers -L../../../Lib -lPDFNetC -lstdc++ -lpthread -lm -lc -Wl,-rpath,../../../Lib -Wl,-rpath$ORIGIN -o myApp
  1. Run the application via ./myApp. The output should read:

sh

1PDFNet is running in demo mode.
2Permission: write
3Hello World!

Check the output.pdf that the program output in the same directory. It should be a PDF with one blank page.

Next step

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales

On this page