title: How to insert an PDPage within another PDPage with pdfbox
body: <p>I use different tools like processing to create vector plots. These plots are written as single or multi-page pdfs. I would like to include these plots in a single report-like pdf using pdfbox.</p>
  
  <p>My current workflow includes these pdfs as images with the following pseudo code</p>
  
  <pre><code>PDDocument inFile = PDDocument.load(file);
  PDPage firstPage = (PDPage) inFile.getDocumentCatalog().getAllPages().get(0);
  BufferedImage image = firstPage.convertToImage(BufferedImage.TYPE_INT_RGB, 300);
  PDXObjectImage ximage = new PDPixelMap(document, image);
  
  PDPageContentStream contentStream = new PDPageContentStream(document, page);
  contentStream.drawXObject(ximage, 0, 0, ximage.getWidth(), ximage.getHeight());
  contentStream.close();
  </code></pre>
  
  <p>While this works it looses the benefits of the vector file formats, espectially file/size vs. printing qualitity.</p>
  
  <p>Is it possible to use pdfbox to include other pdf pages as embedded objects within a page (Not added as a separate page)? Could I e.g. use a PDStream? I would prefer a solution like pdflatex is able to embed pdf figures into a new pdf document.</p>
  
  <p>What other Java libraries can you recommend for that task?</p>