We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Creating New Document from inputsteam taking long time to create PDF

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;

}

@ryangoris

Can you please share values of pages width, height, margins, definition for addDigitalSignatureField and sample HTML so that we may try to reproduce the same on our end.

summary form merged html example.zip (1.5 KB)

#################################################################################

public byte[] createPdfFromHtml(String inputHtml, String cssDir) throws IOException {
byte[] returnBytes = null;

//default margins for Portrait
float marginLeftPortrait = 36;
float marginRightPortrait = 36;
float marginTopPortrait = 36;
float marginBottomPortrait = 36;

//cssDir is the full path to the css folder
HtmlLoadOptions options = new HtmlLoadOptions(cssDir);

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

return returnBytes;

}

@ryangoris

I request you to upgrade to latest version because the PDF file is created on my end within 25 seconds. test.pdf (120.1 KB)