This commit is contained in:
John Whitington 2022-04-04 19:29:49 +02:00
parent a5916998ae
commit 7a62b5ab47
2 changed files with 30 additions and 21 deletions

Binary file not shown.

View File

@ -4,7 +4,7 @@
\excludecomment{cpdflib} \excludecomment{cpdflib}
\excludecomment{pycpdflib} \excludecomment{pycpdflib}
\excludecomment{dotnetcpdflib} \excludecomment{dotnetcpdflib}
\includecomment{jcpdflib} \excludecomment{jcpdflib}
\usepackage{palatino} \usepackage{palatino}
\usepackage{listings} \usepackage{listings}
\usepackage{microtype} \usepackage{microtype}
@ -486,32 +486,41 @@ document with the original included three times.
\begin{small} \begin{small}
\begin{verbatim} \begin{verbatim}
//Merge example //Merge example
using System; import Jcpdf
using System.Collections.Generic;
using CoherentGraphics;
// Initialise cpdf public static void main(String[] args)
Cpdf.startup();
// We will take the input hello.pdf and repeat it three times
using (Cpdf.Pdf mergepdf = Cpdf.fromFile("hello.pdf", ""))
{ {
// The list of PDFs to merge // Initialise cpdf
List<Cpdf.Pdf> pdfs = new List<Cpdf.Pdf> {mergepdf, mergepdf, mergepdf}; 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 // Merge them
Cpdf.Pdf merged = Cpdf.mergeSimple(pdfs); Jcpdf.Pdf merged = jcpdf.mergeSimple(pdfs);
// Write output // Write output
Cpdf.toFile(merged, "merged.pdf", false, false); jcpdf.toFile(merged, "merged.pdf", false, false);
// Dispose of merged PDF // Dispose of merged PDF
merged.Dispose(); merged.close();
}
catch (Jcpdf.CpdfError e)
{
System.out.println("Error during cpdf operation");
}
} }
\end{verbatim} \end{verbatim}
\end{small} \end{small}
\noindent Note the use of \texttt{using} and \texttt{Dispose()} to ensure the PDFs are thrown away when no longer required. \noindent Note the use of \texttt{try} and \texttt{close()} to ensure the PDFs are thrown away when no longer required.
\end{jcpdflib} \end{jcpdflib}
\pagestyle{plain} \pagestyle{plain}