Aspose PDF "new Document(Steam input, LoadOptions options)" performance very slow

Using Aspose.PDF 18.9.1.0 for a .NET Core app. Using Aspose to create a PDF from a Stream in the following code:

            var options = GetHtmlOptions(pageWidth, pageHeight);
            var manager = new RecyclableMemoryStreamManager();

            Document pdfDoc = null;
            for (var index = 0; index < htmlPages.Count; index++) // using for loop instead of foreach to increase performance
            {
                var page = htmlPages[index];
                var sourceBuffer = Encoding.UTF8.GetBytes(page);
            using (var ms = manager.GetStream(null, sourceBuffer, 0, sourceBuffer.Length))
            {
                var doc = new Document(ms, options);
                if (pdfDoc == null) {
                    pdfDoc = doc;
                }
                else {
                    pdfDoc.Pages.Add(doc.Pages);
                }
            }
        }

The specific line: var doc = new Document(ms, options); takes a very long time to complete and causes a bottleneck for the rest of the application. What can I do to improve the performance of creating a new PDF?

@jkurian,

Can you please share source file so that we may further investigate to help you out. Also please try to use Aspose.PDF latest version 20.1 on your before sharing requested information.

1 Like

I don’t have the ability to update to Aspose.PDF 20.1 due to license restrictions. But I have attached the source file. PdfConversionService.zip (1.2 KB)

@jkurian,

I like to inform that support is always provided based on latest version. Please try to use latest version on your end. This will resolve your issue as well. You may use trial license with latest version of product.

I’m experiencing the same issue using the latest version of Aspose.PDF 23.4.0 for a .NET Core project as an Azure Function App. We’re currently in a trial trying to investigate possible packages to use for PDF splitting/merging as well as barcode reading.

Following scenarios using a PDF file at size 13.75 MB with 338 pages.
I noticed if I do string RESOURCE = "../../../10840_1.pdf"; using Document pdfDoc = new(RESOURCE); it takes under a second to process that line.
However, if I change “RESOURCE” to a stream of a file pulled from Azure Blob. Then that line of code takes a little over 5 mins to process.

@hstrachn

Can you please share a sample application that can reproduce the same issue that you are facing including a sample PDF document? It will help us in testing the scenario and address it accordingly.