title: Splitting a pdf with pdfbox, but losing the font
body: <p>I wrote some code in Java using the pdfbox API that splits a pdf document into it's individual pages, looks through the pages for a specific string, and then makes a new pdf from the page with the string on it.  My problem is that when the new page is saved, I lose my font.  I just made a quick word document to test it and the default font was calibri, so when I run the program I get an error box that reads: "Cannot extract the embedded font..." So it replaces the font with some other default.</p>
  
  <p>I have seen a lot of example code that shows how to change the font when you are inputting text to be placed in the pdf, but nothing that sets the font for the pdf.  </p>
  
  <p>If anyone is familiar with a way to do this, (or can find documentation/examples), I would greatly appreciate it!</p>
  
  <p>Edit: forgot to include some sample code</p>
  
  <pre><code>if (pageContent.indexOf(findThis) &gt;= 0){
                  PDPage pageToRip = pages.get(i);
                  &gt;&gt;set the font of pageToRip here
                  res.importPage(pageToRip); //res is the new document that will be saved
              }
  </code></pre>
  
  <p>I don't know if that helps any, but I figured I'd include it.</p>
  
  <p>Also, this is what the change looks like if the pdf is written in calibri and split:</p>
  
  <p><img src="https://i.stack.imgur.com/kagFq.png" alt="left:calibri, right:what it changes to"></p>
  
  <p><strong>Note: This might be a nonissue, it depends on the font used in the files that will need to be processed.  I tried some things besides Calibri and it worked out fine.</strong>  </p>