PDF Command Line Tools

Download Free Trial
Buy Now
Read Manual
Blog
Resellers
Custom Development
News Archive
Links
Free PDF Library
Command Line Manual (HTML)

PDF Command Line Tools Usage Examples

Back to main page

Here are some examples of the Coherent PDF C API in action. For more instructions, see the Full PDF Manual.

#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;
}

Read the file hello.pdf and triplicate it, writing to merged.pdf

/* Squeeze the manual. */
#include <stdbool.h>
#include "cpdflibwrapper.h"

int main (int argc, char ** argv)
{
/* Initialise cpdf */
cpdf_startup(argv);

/* Clear the error state */
cpdf_clearError();

/* Use the cpdflib manual as an example. */
int pdf = cpdf_fromFile("cpdflibmanual.pdf", "");

/* Check the error state */
if (cpdf_lastError) return 1;

cpdf_clearError();

/* Squeeze it */
cpdf_squeezeInMemory(pdf);

/* Check the error state */
if (cpdf_lastError) return 1;

/* Clear the error state */
cpdf_clearError();

/* Write output. We make sure to use toFileExt, and make object streams. */
cpdf_toFileExt(pdf, "squeezed.pdf", false, false, true, true, true);

/* NOTE that the in-memory document 'pdf' is now defunct, following the call
to toFileExt, so we must remove it. */
cpdf_deletePdf(pdf);

/* Check the error state */
if (cpdf_lastError) return 1;

return 0;
}

Read the file cpdflibmanual.pdf and squeeze it, writing to squeezed.pdf