This program loads a file hello.pdf from disk and writes out a document with the original included three times.
//Merge example
import com.coherentpdf.Jcpdf
public static void main(String[] args)
{
// Initialise cpdf
Jcpdf jcpdf = new Jcpdf();
try
{
jcpdf.startup();
}
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
merged.close();
}
catch (Jcpdf.CpdfError e)
{
System.out.println("Error during cpdf operation");
}
}
Note the use of try and close() to ensure the PDFs are thrown away when no longer required.