title: How to reduce the size of merged PDF/A-1b files with pdfbox or other java library
body: <p><strong>Input</strong>: A list of (e.g. 14) PDF/A-1b files with embedded fonts.<br>
  <strong>Processing</strong>: Doing a simple merge with Apache PDFBOX.<br>
  <strong>Result</strong>: 1 PDF/A-1b file with large (too large) file size. (It is almost the sum of the size of all the source files).</p>
  
  <p><strong>Question</strong>: Is there a way to reduce the file size of the resulting PDF?<br>
  <strong>Idea</strong>: Remove redundant embedded fonts. But how to? And is it the right way to do?</p>
  
  <p>Unfortunately the following code is not doing the job, but is highlighting the obvious problem.</p>
  
  <pre><code>try (PDDocument document = PDDocument.load(new File("E:/tmp/16189_ZU_20181121195111_5544_2008-12-31_Standardauswertung.pdf"))) {
      List&lt;COSName&gt; collectedFonts = new ArrayList&lt;&gt;();
      PDPageTree pages = document.getDocumentCatalog().getPages();
      int pageNr = 0;
      for (PDPage page : pages) {
          pageNr++;
          Iterable&lt;COSName&gt; names = page.getResources().getFontNames();
          System.out.println("Page " + pageNr);
          for (COSName name : names) {
              collectedFonts.add(name);
              System.out.print("\t" + name + " - ");
              PDFont font = page.getResources().getFont(name);
              System.out.println(font + ", embedded: " + font.isEmbedded());
              page.getCOSObject().removeItem(COSName.F);
              page.getResources().getCOSObject().removeItem(name);
          }
      }
      document.save("E:/tmp/output.pdf");
  }
  </code></pre>
  
  <p>The code produces an output like that:<br></p>
  
  <pre class="lang-none prettyprint-override"><code>Page 1
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 2
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F33} - PDTrueTypeFont ArialMT-BoldItalic, embedded: true
      COSName{F25} - PDTrueTypeFont ArialMT-Italic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 3
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F25} - PDTrueTypeFont ArialMT-Italic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 4
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F25} - PDTrueTypeFont ArialMT-Italic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 5
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F33} - PDTrueTypeFont ArialMT-BoldItalic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 6
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F33} - PDTrueTypeFont ArialMT-BoldItalic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 7
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F33} - PDTrueTypeFont ArialMT-BoldItalic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 8
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F25} - PDTrueTypeFont ArialMT-Italic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 9
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F33} - PDTrueTypeFont ArialMT-BoldItalic, embedded: true
      COSName{F25} - PDTrueTypeFont ArialMT-Italic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 10
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F33} - PDTrueTypeFont ArialMT-BoldItalic, embedded: true
      COSName{F25} - PDTrueTypeFont ArialMT-Italic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 11
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F33} - PDTrueTypeFont ArialMT-BoldItalic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 12
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F25} - PDTrueTypeFont ArialMT-Italic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 13
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F25} - PDTrueTypeFont ArialMT-Italic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  Page 14
      COSName{F23} - PDTrueTypeFont ArialMT-Bold, embedded: true
      COSName{F25} - PDTrueTypeFont ArialMT-Italic, embedded: true
      COSName{F27} - PDTrueTypeFont ArialMT-Regular, embedded: true
  </code></pre>
  
  <p>Any help appreciated ...</p>