When I convert an HTML file to a PDF, it seems that the images are not resized to the correct PDF page size and just get cut off, if they are too large.
@bennetpe There is no way to scale the images automatically upon loading document. However, you can easily do this in your code. For example see the following code:
Document doc = new Document("C:\\Temp\\test.html");
// Get all shapes in the document.
Iterable<Shape> shapes = doc.getChildNodes(NodeType.SHAPE, true);
for (Shape s : shapes)
{
Section parentSection = (Section)s.getAncestor(NodeType.SECTION);
PageSetup ps = parentSection.getPageSetup();
double maxWidth = ps.getPageWidth() - ps.getLeftMargin() - ps.getRightMargin();
double scaleFactor = maxWidth / s.getWidth();
if (scaleFactor < 1)
{
s.setAspectRatioLocked(true);
s.setWidth(s.getWidth() * scaleFactor);
}
}
doc.save("C:\\Temp\\out.pdf");
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.