Convert from html to pdf set image size

This is what I'm trying to do: Take an html document with an image as input and
output a pdf with a specific size.
This is a sketch of my code at the moment:

String pdfPath = "some/path";
String htmlPath = "some/other/path";
String name = "Name_of_File";

HtmlLoadOptions htmlOptions = new HtmlLoadOptions(tempPath);
Document pdf = new Document(htmlPath+File.separator+name, htmlOptions);
Page pdfPage = pdf.getPages().get_Item(1);
pdfPage.setPageSize(100.0, 100.0); + File.separator + name + ".pdf");

The result is fine, when I don't specify the size, and the pdf defaults to A4, but
when I specify the size of the pdf, the image is not resized accordingly.
How do I make it so that the image is properly rendered in the correct size
when the pdf is resized?

Hi Jon,

Thanks for your inquiry. Please note setPageSize is used for an existing PDF document. To control output PDF page size while converting HTML to PDF you need to use PageInfo object of HtmlLoadOptions class as following. It will help you to accomplish the task.


HtmlLoadOptions htmlOptions = new HtmlLoadOptions(tempPath);




Please feel free to contact us for any further assistance.

Best Regards,

thank you for your response, it now works.

Best regards,

Hi Jon,

We are glad to hear that your problem is resolved. Please continue using our API and should you have any further query, please feel free to contact.