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

Free Support Forum - aspose.com

Poor Performance with TextBuilder

We are currently using Aspose.Pdf in a process that we use to merge text on top of a template pdf file. Due to the poor performance of the process, we've been tasked to look at other options and also determine the source of the performance issue.

With the Aspose.Pdf library, the total process for one particular report is around 12 seconds. This is a 50 page report. We used a competitor's library to achieve the same result and it takes only 3 seconds to build the same report.

As the report to be rendered grows larger in size (a production report can be > 1000 pages) the time that it takes for the processing using Aspose increases dramatically, making not feasible to use the product in production.

We have found that the TextBuilder.AppendText method is very slow compared to other competitors products.

Here is a snippet of the code we are using:

....
Log.Write("1 - Get TextBuilder");
if (page != currentPage)
{
//Log.Write("1.1");
currentPage = page;
currentTextBuilder = new TextBuilder(currentPage);
}
//TextBuilder textBuilder = new TextBuilder(page);
Log.Write("2 - Before TextBuilder.AppendText");
//textBuilder.AppendText(textFragment);
currentTextBuilder.AppendText(textFragment);
Log.Write("3 - After TextBuilder.AppendText");
....

This results in a log file that looks like this:

10/27/2015 10:35:42:4358 - 1 - Get TextBuilder
10/27/2015 10:35:42:4368 - 2 - Before TextBuilder.AppendText
10/27/2015 10:35:42:4378 - 3 - After TextBuilder.AppendText
10/27/2015 10:35:42:4378 - 1 - Get TextBuilder
10/27/2015 10:35:42:4378 - 2 - Before TextBuilder.AppendText
10/27/2015 10:35:42:4388 - 3 - After TextBuilder.AppendText
10/27/2015 10:35:42:4388 - 1 - Get TextBuilder
10/27/2015 10:35:42:4388 - 2 - Before TextBuilder.AppendText
10/27/2015 10:35:42:4398 - 3 - After TextBuilder.AppendText
10/27/2015 10:35:42:4398 - 1 - Get TextBuilder
10/27/2015 10:35:42:4398 - 2 - Before TextBuilder.AppendText
10/27/2015 10:35:42:4408 - 3 - After TextBuilder.AppendText
10/27/2015 10:35:42:4418 - 1 - Get TextBuilder
10/27/2015 10:35:42:4418 - 2 - Before TextBuilder.AppendText
10/27/2015 10:35:42:4418 - 3 - After TextBuilder.AppendText

Then we use a the competitors product. Here is example code from that process:

....
Phrase text = new Phrase(value, iTextFont);
Log.Write("1 - Before ShowTextAligned");
ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, text, field.StartX + horizontalAdjustment, height - verticalAdjustment - field.StartY, 0);
Log.Write("2 - After ShowTextAligned");
....

This results in a log file that looks like this:

10/27/2015 10:35:30:1859 - 1 - Before ShowTextAligned
10/27/2015 10:35:30:1859 - 2 - After ShowTextAligned
10/27/2015 10:35:30:1859 - 1 - Before ShowTextAligned
10/27/2015 10:35:30:1859 - 2 - After ShowTextAligned
10/27/2015 10:35:30:1859 - 1 - Before ShowTextAligned
10/27/2015 10:35:30:1859 - 2 - After ShowTextAligned
10/27/2015 10:35:30:1869 - 1 - Before ShowTextAligned
10/27/2015 10:35:30:1869 - 2 - After ShowTextAligned
10/27/2015 10:35:30:1869 - 1 - Before ShowTextAligned
10/27/2015 10:35:30:1869 - 2 - After ShowTextAligned
10/27/2015 10:35:30:1869 - 1 - Before ShowTextAligned
10/27/2015 10:35:30:1869 - 2 - After ShowTextAligned
10/27/2015 10:35:30:1869 - 1 - Before ShowTextAligned
10/27/2015 10:35:30:1869 - 2 - After ShowTextAligned

As you can see, this product has much faster performance.

If I run the full report, which is 6622 pages, not just the 50 pages for testing, the entire process takes 18 minutes and the resulting pdf file is 365mb without optimization and ~80mb with optimization. The optimization process consumes a massive amount of memory (all the memory that was available on my machine, 6+ gb) and also takes another hour or two to complete.

The competitor's product takes 19 seconds and the resulting pdf file is 7mb. No optimization is required.

Both PDFs have 6622 pages and look identical.

Is there a better way for us to write this code to make it run faster? Why is there such a large difference in the size of the final rendered pdf?

Thank You.


For completeness, optimization code is as follows:

mainDoc.OptimizeResources(new Document.OptimizationOptions()
{
LinkDuplcateStreams = true,
RemoveUnusedObjects = true,
RemoveUnusedStreams = true,
});

Hi Steve,


Thanks for contacting support.

Can you please share the resource PDF file, so that we can test the scenario in our environment. We are sorry for this inconvenience.

I will get you an example of a gerneated PDF that exhibits these symptoms and then a pdf built with the other library.

Attached is a sample of a rendered pdfs from both products that exhibits the issues with speed and file size. Log files are included for both to show time it take to render these reports. Please let me know if there’s anything else you need from me.

Hi Steve,


Thanks for sharing the resource files.

I am able to observe the difference in size of output generated with Aspose and competitor’s product but in order for us to further optimize the PDF manipulation process, we need to replicate the scenario in our environment. So we request you to please share some sample project, so that we can test the scenario in our environment.

Attached is a generic example that shows how our application is written. It uses the aspose library and the competitors library to render the same report.


You will have to include an aspose embedded license file to allow the program to run.

Please let me know if you have any questions, or if there is anything that we can do to improve our process to get results similar to the other product.

Thank you.

Hi Steve,

Thanks for your sharing the resource files.

I have tested the scenario of PDF file creation and have managed to reproduce performance and large size file generation issues. For the sake of correction, I have separately logged them as

  • PDFNEWNET-39633 - Slow performance when adding text to PDF file
  • PDFNEWNET-39634 - PDF file generated with Aspose is larger in size as compared to competitor product.

We will further look into the details of these issues and will keep you posted on the status of correction. Please be patient and spare us little time. We are really sorry for this inconvenience.