CIB pdf toolbox technical guide (EN)
18. Quick start
18.1. Integration of the CIB pdf toolbox al C++ code example
Static linking of the CIB pdf toolbox
Description of the code example
General
The following example demonstrates the control of the CIB pdf toolbox under C++.
The files used in the code example are adapted to the examples included in the scope of delivery, thus ensuring immediate functionality for test purposes.
The code example was translated in Microsoft Visual Studio C++ 6.0. The project file for this development environment is also included.
For an integration into your own project please note:
- Should the dll be applied statically or dynamically? The code example uses the static inclusion.
- Connection to the own error handling. The code example contains a minimal text-based error output. The handling of error codes is demonstrated here.
- Connection to the own document requirements. The code example contains hard-coded file names and is for demonstration purposes only. The administration must be completely adapted to your own requirements
Note:
This example represents a functioning overall process. For information on how to search for individual functions and their possible variants, please refer to the documentation, help and CIB Support.
Static linking of the CIB pdf toolbox
// CibPdfDll.cpp : Loads the CIB pdf toolbox statically from a specific path
#include “stdafx.h”
#include <stdio.h>
#include <windows.h>
#include “CibPdfDll.h”
// Samplepdftoolbox.cpp : Defines the entry point for the console application.
//
#include “stdafx.h”
#include <stdio.h>
#include <windows.h>
#include “..\bin\cibpdf.h”
int main(int argc, char* argv[])
{
printf(„Performing the pdfmerge XML samples:\r\n\r\n“);
//Generate a separate output file for each record (true)
BOOL t_bRet = CibPdfSetProperty(“MultiOutput”, “1”);
//Specification of the PdfMerge input request, such as XML:data.xml;<xpath>
t_bRet &= CibPdfSetProperty(“Data”, “XML:..\\merge xml\\data.xml;//Testdaten//Person”);
//Specifying the input file
t_bRet &= CibPdfSetProperty(„InputFilename“,“““..\\merge xml\\test.pdf“““);
//Specifying the output file
t_bRet &= CibPdfSetProperty(„OutputFilename“,“..\\tempoutput\\mergeXMLoutput.pdf“);
if(!t_bRet)
{
printf(„Error when setting the properties for CIB pdf merge\r\n\r\n“);
getchar();
return 0;
}
//Performing the merge run
t_bRet = CibPdfMerge();
if(t_bRet)
{
printf(„Status:\r\nCIB pdf merge successfully implemented in mergeXMLoutput.pdf durchgefuehrt\r\n“);
printf(„Please press [Return] to continue the demo\r\n\r\n“);
getchar();
}
else
{
int t_FehlerNr;
if(!CibPdfGetLastError(&t_FehlerNr))
{
printf(„Error occurred. The error number cannot be read out“);
getchar();
return 0;
}
printf(„Error %d while performing CIB pdf merge\r\n“, t_FehlerNr);
const int t_BufferLength = 1024;
char t_Fehlertext[t_BufferLength];
if( !CibPdfGetErrorText(t_FehlerNr, t_Fehlertext, t_BufferLength))
{
printf(„Error occurred. The error number cannot be read out“);
getchar();
return 0;
}
printf(„Error: %s“, t_Errortext);
getchar();
return 0;
}
printf(„Performing the CIB pdfjoin sample:\r\n“);
//Of the 3 input files, the first is encrypted. Therefore pass a password
t_bRet = CibPdfSetProperty(„EncryptOwnerPassword“, „test1o;;“);
//The output file should be encrypted (Userpassword), // i.e. it is queried by the reader when opening)
t_bRet &= CibPdfSetProperty(“OutputUserPassword”, “outputu”);
//Specification of the 3 input files
t_bRet &= CibPdfSetProperty(„InputFilename“,
„..\\join\\test1.pdf;..\\join\\funktionstest1.pdf;..\\join\\functionstest2.pdf“);
//Specifying the output file name
t_bRet &= CibPdfSetProperty(„OutputFilename“,“..\\tempoutput\\joinoutput.pdf“);
if(!t_bRet)
{
printf(„Error setting the properties for CIB pdf join\r\n\r\n“);
getchar();
return 0;
}
//Perform the Join
t_bRet = CibPdfJoin();
if(t_bRet)
{
printf(„\r\nStatus:\r\nCIB pdf join conducted successfully in joinoutput.pdf \r\n“);
printf(„Please press [Return] to continue the demo\r\n\r\n\r\n“);
getchar();
}
else
{
int ErrorNr;
if(!CibPdfGetLastError(&ErrorNr))
{
printf(„Error occurred. The error number cannot be read out“);
getchar();
return 0;
}
printf(„Error %d while running CIB pdf join\r\n“, t_ErrorNr);
const int t_BufferLength = 1024;
char Errortext[t_BufferLength];
if( !CibPdfGetErrorText(t_FehlerNr, t_Errortext, t_BufferLength))
{
printf(„Error occurred. The error text cannot be read out“);
getchar();
return 0;
}
printf(„Error: %s“, t_Errorrtext);
getchar();
return 0;
}
printf(„End of the demo.\r\n“);
getchar();
return 0;
}
Description of the code example
The code example first controls the example 'merge xml' which is stored in the transfer package. The data contained in the XML file 'data.xml' is merged into the form 'test.pdf'. A result document mergeXMLoutput00001.pdf is created for each data record contained in the form. The appended number per data record is ascending. If the 'MultiOutput' property is set to FALSE, only one output file is generated and no number is appended.
Afterwards the example 'join' is used. The 3 files 'test1.pdf', 'Funktionstest1.pdf' and 'Funktionstest2.pdf' are attached to each other. For the encrypted input file 'test1.pdf' the password is specified and the resulting output file 'joinoutput.pdf' is also encrypted with a password.
The output files resulting from both runs are stored in the directory ' tempoutput'.