PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Version 1.3.0 adds setPageMargins(top, right, bottom, left) and getPageMargins() to CConverterProperties. Margins are measured in CSS pixels and repeat on every page. Page width and height passed to setPageSize() are measured in points. Explicit margins in the document's CSS @page rules take precedence over these property values.
import CPDFGeneration.CConverterProperties;
import CPDFGeneration.CHtmlConverter;
CConverterProperties properties = new CConverterProperties();
try {
properties.setPageMargins(48, 40, 48, 40);
int[] margins = properties.getPageMargins();
System.out.println("Top margin: " + margins[0] + " CSS px");
CHtmlConverter.CErrorCode status = CHtmlConverter.ConvertToPdf(
"input.html", "margins.pdf", properties);
if (status != CHtmlConverter.CErrorCode.HTML_CONVERTER_SUCCESS) {
throw new IllegalStateException("HTML conversion failed: " + status);
}
} finally {
properties.release();
}All four margins must be nonnegative. getPageMargins() returns a new array in top/right/bottom/left order; changing that array does not update the properties. A newly created CConverterProperties has zero margins. Email conversion without a properties object uses its own defaults, described in Email Conversion.
Keep the properties and any assigned font provider valid throughout conversion. Release the properties after use, as shown above.