title: Inserting multiple copies of a page into a PDF
body: <p>As far as I know, PDFs support references to objects. So, for example, if I use the same image 100 times in a document - it can be optimized to use same image in each place greatly saving PDF size.</p>
  
  <p>Does PDF support the same with full pages of data? If yes, how can I do it with iText library?</p>
  
  <p>My problem is, I have a huge document of ~500 pages, and every 2-3 pages I need to insert <strong>the same</strong> template page that is read from other PDF document. The code looks likes this:</p>
  
  <pre><code>    protected static void addAppendix(PdfWriter writer, Document document, InputStream appendixStream)
              throws IOException {
          PdfContentByte cb = writer.getDirectContent();
          PdfReader reader = new PdfReader(appendixStream);
          for (int idx = 1; idx &lt;= reader.getNumberOfPages(); ++idx) {
              document.newPage();
              PdfImportedPage imported = writer.getImportedPage(reader, idx);
              cb.addTemplate(imported, 0, 0);
          }
          writer.freeReader();
      }
  </code></pre>
  
  <p>However, this increases the PDF size greatly, especially if the appendix contains some large images and stuff. Is there any way to somehow optimize the size of my document?</p>