This program loads a file hello.pdf from disk and writes out a document with the original included three times. Note the use of cpdf_startup, cpdf_lastError and cpdf_clearError.
#include <stdbool.h> #include "cpdflibwrapper.h" int main (int argc, char ** argv) { /* Initialise cpdf */ cpdf_startup(argv); /* We will take the input hello.pdf and repeat it three times */ int mergepdf = cpdf_fromFile("hello.pdf", ""); /* Check the error state */ if (cpdf_lastError) return 1; /* Clear the error state */ cpdf_clearError(); /* The array of PDFs to merge */ int pdfs[] = {mergepdf, mergepdf, mergepdf}; /* Merge them */ int merged = cpdf_mergeSimple(pdfs, 3); if (cpdf_lastError) return 1; cpdf_clearError(); /* Write output */ cpdf_toFile(merged, "merged.pdf", false, false); if (cpdf_lastError) return 1; return 0; }