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);

pdf.save(pdfPath + 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?
Thanks.


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 the PageInfo object of the HtmlLoadOptions class.s It will help you accomplish the task.

HtmlLoadOptions htmlOptions = **new** HtmlLoadOptions(tempPath);
htmlOptions.getPageInfo().setHeight(100);
htmlOptions.getPageInfo().setWidth(100);

Please feel free to contact us for any further assistance.

Best Regards,

Hi,
thank you for your response, it now works.

Best regards,
Jon

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.