PDF Command Line Tools

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

Coherent PDF Java API Usage Example

Back to main page

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

//Merge example
import com.coherentpdf.Jcpdf

public static void main(String[] args)
   // Initialise cpdf
   Jcpdf jcpdf = new Jcpdf();
   catch (Jcpdf.CpdfError e)
     System.out.println("Error during cpdf startup");
   // We will take the input hello.pdf and repeat it three times
   try (Jcpdf.Pdf mergepdf = jcpdf.fromFile("hello.pdf", ""))
     // The array of PDFs to merge
     Jcpdf.Pdf[] pdfs = {mergepdf, mergepdf, mergepdf};
     // Merge them
     Jcpdf.Pdf merged = jcpdf.mergeSimple(pdfs);
     // Write output
     jcpdf.toFile(merged, "merged.pdf", false, false);
     // Dispose of merged PDF
   catch (Jcpdf.CpdfError e)
     System.out.println("Error during cpdf operation");

In Java, read the file hello.pdf and triplicate it, writing to merged.pdf