
In this Java tutorial, we will convert an apple SVG logo to PDF, resize it and place it in the top-left corner of an example PDF invoice. We will use the Apache Batik and iText libraries.
1) Convert the SVG logo to PDF
Add the following dependencies to your POM :
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-codec</artifactId>
<version>1.13</version>
</dependency>
Then the convert logic is simply (replace SVG_PATH and PDF_PATH with your own values) :
A PDF file with path PDF_PATH is generated and it contains the exact same logo as in the file with path SVG_PATH.
2) Resize the PDF logo
In my case, the obtained PDF logo has a size of 300 x 300, while an A4 page has a size of 595 x 842. My PDF logo is currently very big and I want to make it smaller so that it fits nicely in the top-left corner of my final invoice PDF (as shown in the picture above). So we are going to generate a second PDF file, that will be smaller than the current PDF logo, and with same aspect ratio. Let's use the iText library and perform an affine transformation. First add the following dependencies to your POM :
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>7.1.5</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>7.1.5</version>
</dependency>
The shrink logic is the following (replace the strings PDF_PATH, PDF_SHRINKED_PATH and the double RATIO with your own values) :
A PDF file with path PDF_SHRINKED_PATH is generated and it contains the same PDF logo but resized. In my case I used RATIO=0.22, and my resulting resized logo now has a size of 66x66 (versus 300x300 originally). We can see the difference in size below :

3) Add the logo to the top-left corner of an A4 page
Let's add the resized logo to the top-left corner of an A4 PDF page (replace LOGO_PATH and INVOICE_PATH with your own values) :
An A4 PDF file with path INVOICE_PATH is generated, and it contains an apple logo in the top-left corner.
Now you have all the tools to automatically build in Java your own professional PDF documents starting from SVG logos. You can then add text and tables for example by using the awesome iText library. If you need help with your code, leave us a reply, we reply within 24 hours.