Hi Aspose Team!
Posting our question here as the support for our 11.9 OEM license has expired, and would like to know the answer to this question before renewing…
We have the need to produce some pretty large PDF documents that we are currently producing using HTML and styling with CSS. Given some experimentation, there seems like a direct correlation in the performance the library and the amount of CSS provided. I ran a few different tests on a 80 page PDF:
- HTML to PDF - With CSS table styles - ~30 secs
test.pdf (512 KB)
- HTML to PDF - With CSS table styles and embedded base64 images - ~30 secs
test-with-base64-images.pdf (2 MB)
- HTML to PDF - No CSS - ~10 secs
test-with-no-css.pdf (2 MB)
- HTML to PDF - Extra CSS - ~250 secs
Loaded FontAwesome all.css even though no elements used any classes - no file attached.
- HTML to PDF - CSS applied inline on HTML elements - ~30 secs
File not included, not the best test since copying all the styles onto the elements would have been a lot of work, but I think I did enough to get a gauge that the performance was similar to having the styles in CSS.
All the files included here: test.zip (1.4 MB)
I totally understand we are on an older version, so I am curious what our best plan moving forward is. I’m not expecting performance miracles rendering a 1500 page PDF, but making sure we are not using the API in an unwise way. There obviously is a direct correlation to the amount of CSS in the HTML and render time - even if the CSS is not used. Many moons ago when we were initially working on PDF performance we did see a performance hike rending the CSS inline rather than referencing an external CSS file.
We have experimented primarily with two different methods - Stream + Flatten and Page + HtmlFragment. We saw slightly better performance (maybe 15%) using HtmlFragment but the code below seemed to produce the best results for our markup.
var html = RenderView(viewName, model);
var buffer = Encoding.UTF8.GetBytes(html);
var instream = new MemoryStream(buffer);
var options = new HtmlLoadOptions();
options.PageInfo.Width = Aspose.Pdf.Generator.PageSize.LetterWidth;
options.PageInfo.Height = Aspose.Pdf.Generator.PageSize.LetterHeight;
options.PageInfo.Margin.Top = 35;
options.PageInfo.Margin.Bottom = 40;
options.PageInfo.Margin.Right = 35;
options.PageInfo.Margin.Left = 35;
var doc = new Document(instream, options);
doc.Flatten();
var outstream = new MemoryStream();
doc.Save(outstream);
Here are my questions:
-
Is there a better use of the 11.9 library that would render the CSS faster?
-
What is the best pattern to use in the newest version?
-
Since the trial limits page length - is there a way I can test the newest library version for extra large documents?
I’m not looking for performance miracles, but instead advice of how to best to HTML to PDF conversions as going bare metal with the API and drawing PDFs is not a real option.
Thanks in advance team - I look forward to your response.
-Max