I am able to add the SVG image in PDF using the below code but alignment of image is going for a toss. I would like to keep image in a confined area (let's say 300 x 300 size always). If image is bigger, it should shrink/compress and fit into this size. How can we achieve this.
PdfDocument doc = null;
try {
doc = new PdfDocument(new PdfWriter(new FileOutputStream(new File("D:\\test.pdf")),
new WriterProperties().setCompressionLevel(0)));
doc.addNewPage();
URL svgUrl = null;
String svgPath = "...svgPathHere";
try {
svgUrl = new URL(svgPath);
} catch(MalformedURLException mue) {
System.out.println("Exception caught" + mue.getMessage() );
}
if (svgUrl == null){
try {
svgUrl = new File(svgPath).toURI().toURL();
} catch(Throwable th) {
System.out.println("Exception caught" + th.getMessage());
}
}
SvgConverter.drawOnDocument(svgUrl.openStream(), doc, 1, 100, 200); // 100 and 200 are x and y coordinate of the location to draw at
doc.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Adding to the same above question, drawOnDocument() method of SvgConverter provides us the control to postion our svg through x and y cordinates. Is there a better way to handle postioning? (like Top-left, Top-right)