The Document doc = new Document(is, options) line of code is taking a long time to complete. We are seeing 5 minutes to complete. Below is the code we have to create a pdf. In the code ‘is’ is defines as a ByteArrayInputStream just for awareness. Thoughts on why it is taking too long?
public byte[] createPdfFromHtml(String inputHtml, String cssDir, boolean isLandscape) throws IOException {
byte[] returnBytes = null;
//cssDir is the full path to the css folder
HtmlLoadOptions options = new HtmlLoadOptions(cssDir);
if (isLandscape) {
// set MarginInfo for margin
options.getPageInfo().setWidth(PAGE_WIDTH_LANDSCAPE);
options.getPageInfo().setHeight(PAGE_HEIGHT_LANDSCAPE);
options.getPageInfo().setMargin(new MarginInfo(marginLeftLandscape, marginBottomLandscape, marginRightLandscape, marginTopLandscape));
}
else
options.getPageInfo().setMargin(new MarginInfo(marginLeftPortrait, marginBottomPortrait, marginRightPortrait, marginTopPortrait));
//create the new PDF using the HtmlLoadOptions from above and the inputHTML String
try(ByteArrayInputStream is = new ByteArrayInputStream(inputHtml.getBytes()) ) {
//Create a new PDF input stream from the html
Document doc = new Document(is, options);
PdfPageEditor ppe = new PdfPageEditor();
ppe.bindPdf(doc);
ByteArrayOutputStream bios = new ByteArrayOutputStream();
ppe.save(bios);
returnBytes = bios.toByteArray();
}
//try to add any digital signature fields if they exist in the document
returnBytes = addDigitalSignatureField(returnBytes);
return returnBytes;