title: How to move image to the top of the PDF page using Apache PDFBox?
body: <p>I am using <a href="https://pdfbox.apache.org/" rel="nofollow noreferrer">PDFBox</a> to generate reports in Java. One of my requirements is to create a PDF document which contains the company logo at the top of the page. I am not able to find the way to accomplish that.</p>
  
  <p>I have the following method in a Java class:</p>
  
  <pre><code>public void createPdf() {   
  
          PDDocument document = null;
  
          PDPage page = null;
  
          ServletContext servletContext = (ServletContext) FacesContext
                  .getCurrentInstance().getExternalContext().getContext();
  
          try {
  
              File f = new File("Afiliado_2.pdf");
  
              if (f.exists() &amp;&amp; !f.isDirectory()) {
                  document = PDDocument.load(new File("Afiliado_2.pdf"));
  
                  page = document.getPage(0);
              } else {
  
                  document = new PDDocument();
  
                  page = new PDPage();
  
                  document.addPage(page);
              }
  
              PDImageXObject pdImage = PDImageXObject.createFromFile(
                      servletContext.getRealPath("/resources/images/logo.jpg"),
                      document);
  
              PDPageContentStream contentStream = new PDPageContentStream(
                      document, page, AppendMode.APPEND, true);
  
  
              contentStream.drawImage(pdImage, 0, 0);
  
              // Make sure that the content stream is closed:
              contentStream.close();
  
              // Save the results and ensure that the document is properly closed:
              document.save("Afiliado_2.pdf");
              document.close();
  
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
      }
  </code></pre>
  
  <p>The image is currently appearing in the bottom of the PDF. I know the line I need to modify is <code>contentStream.drawImage(pdImage, 0, 0);</code> but what coordinates do I need to specify so that is appears in the top of the page?</p>