title: PDFlib copy page and use font
body: <p>The PDFlib example <a href="https://www.pdflib.com/tet-cookbook/tet_and_pdflib/search_and_replace_text/" rel="nofollow noreferrer">search and replace text</a> copies pages and pastes rectangles and text.</p>
  <p>Instead of loading a font from my hard disk (like it is done in the example with <code>int font = p.load_font(REPLACEMENT_FONT, &quot;unicode&quot;, &quot;&quot;);</code>) I'd like to use the original font from the source document.</p>
  <p>How can I achieve this?</p>
  <p><strong>What I tried is this:</strong></p>
  <p>When using <code>int font = 0</code> (which is equivalent to the value of <code>tet.fontid</code> in line 244), PDFlib throws an exception like this:</p>
  <pre><code>com.pdflib.PDFlibException: Option 'font' has bad font handle 0
      at com.pdflib.pdflib.PDF_fit_textline(Native Method)
      at com.pdflib.pdflib.fit_textline(pdflib.java:1086)
  </code></pre>
  <p><strong>What could work</strong> (and what I'm also not able to get to run)</p>
  <p>Maybe I could read the fonts in the target document. Reading fonts in source document is feasible with this: <code>(int) lib.pcos_get_number(pdiHandle, &quot;length:fonts&quot;);</code>. Trying to read the fonts in target document with <code>(int) lib.pcos_get_number(outputPdfHandle, &quot;length:fonts&quot;);</code> (with <code>outputPdfHandle = p.begin_document(outfilename, &quot;&quot;)</code> from example line 560) throws exception</p>
  <pre><code>com.pdflib.PDFlibException: Handle parameter or option of type 'PDI document' has bad value 1
      at com.pdflib.pdflib.PDF_pcos_get_number(Native Method)
      at com.pdflib.pdflib.pcos_get_number(pdflib.java:1539)
  </code></pre>