Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is some code that works to copy two files into a merged one with multiple copies of each one. It copies by pages. It's something I got using the information in the answer to this question: <a href="https://stackoverflow.com/questions/14407231/can-duplicating-a-pdf-with-pdfbox-be-small-like-with-itext">Can duplicating a pdf with PDFBox be small like with iText?</a></p> <p>So all you have to do is to make one copy only of the first page of doc1 and one copy only of all pages of doc2. There's a comment where you'll have to make a change to leave off some pages.</p> <pre><code>final int COPIES = 1; // total copies // Same code as linked answer mostly PDDocument samplePdf = new PDDocument(); InputStream in1 = this.getClass().getResourceAsStream(DOC1_NAME); PDDocument doc1 = PDDocument.load(in1); List&lt;PDPage&gt; pages = (List&lt;PDPage&gt;) doc1.getDocumentCatalog().getAllPages(); // *** Change this loop to only copy the pages you want from DOC1 for (PDPage page : pages) { for (int i = 0; i &lt; COPIES; i++) { // loop for each additional copy samplePdf.importPage(page); } } // Same code again mostly InputStream in2 = this.getClass().getResourceAsStream(DOC2_NAME); PDDocument doc2 = PDDocument.load(in2); pages = (List&lt;PDPage&gt;) doc2.getDocumentCatalog().getAllPages(); for (PDPage page : pages) { for (int i = 0; i &lt; COPIES; i++) { // loop for each additional copy samplePdf.importPage(page); } } // Then write the results out File output = new File(OUT_NAME); FileOutputStream out = new FileOutputStream(output); samplePdf.save(out); samplePDF.close(); in1.close(); doc1.close(); in2.close(); doc2.close(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload