title: Generating custom pdf layout with Apache PDFBox Library according to a given template?
body: <p>How can I use the Pdfbox library to generate a custom pdf layout according to a template?</p>
  
  <p>This the template : 
  <a href="https://i.stack.imgur.com/A6saY.png" rel="nofollow noreferrer">layout template</a></p>
  
  <hr>
  
  <p>I am open to using other libraries as well if it has a more elegant way to achieve the result. The project requires to populate a PDF with the data that is fetched from a database, so it would be helpful if the library can assign <code>id's</code> to a particular field in the PDF layout. </p>
  
  <p><strong>For Eg:</strong> In the attached template, having an <code>id = fname</code> for the field <code>Faculty Name</code>so that the data from the database can be added to that particular box instead of padding the text.</p>
  
  <p>What I think is ideal for a problem like this is to have a <code>template.(xml/html)</code> and a library that can generate a PDF parsing that template with their corresponding <code>id's</code>. </p>
  
  <hr>
  
  <p><strong>Candidate libraries I've found:</strong> </p>
  
  <p>1:<a href="https://developers.itextpdf.com/" rel="nofollow noreferrer">iText7</a></p>
  
  <p>2:<a href="https://wkhtmltopdf.org/" rel="nofollow noreferrer">wkhtmltopdf</a></p>
  
  <hr>
  
  <p><strong>The Stack we're using :</strong></p>
  
  <p>Front-End : Thymeleaf template engine with bootstrap</p>
  
  <p>Back-End : Spring-Boot,Hibernate.</p>
  
  <p>Database: H2(for testing)</p>
  
  <p>Build-Tool: Maven</p>
  
  <hr>
  
  <blockquote>
    <p>Now as you have the problem's context, How can I fetch data from the
    database and populate the PDF according to the template?</p>
  </blockquote>