Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library

Frequently Asked Question:

Return to FAQ Index

Vector Graphics for extremely large files.

Question

I am evaluating the QuickPDF library. I have an extremely large file, consisting of about 600,000 lines to render.

In other PDF libraries I have an optimization technique where I group the content by Color/lineWidth/line font, and then only add the path's when they have over 40,000 elements, or at the end of processing the file. This is supported by the libraries returning different path elements that I can then keep adding to, and then when I am done with processing I can add these individual paths to the PDF content. E.G the libraries support having different path elements active at the same time.

I don't see any support for this in QuickPDF. The vector graphics functions all seem to be in immediate mode, with only one path active at a time. The file I have1changes line width constantly, so by default I am ending the current path and creating a new path.

With no caching of the path, it takes QuickPDF 3 minutes to generate the PDF. The average size of the path is 20 points or so. IF I change the code to ignore line width changes, then the time to generate the PDF drops to about 5 seconds.

Is there any way to support this in QuickPDF, or do I need to write my own caching code?

Answer

As you noticed there is no path caching functionality in Quick PDF Library. Internally it has a string object representing the content stream that describes the page. Each time you add a new path the data is converted into string format and appended to the content stream.

One way to improve the speed is to keep the content stream fairly short. The PDF specification allows a page's content stream to be split up into many parts. For historical reasons, Quick PDF Library uses the term "layers" for split content streams.

You can try something like this:

bool newPathCollection = true;
for (int x = 0; x < pathCount; x++)
{
  if (newPathCollection)
  {
    // Set the line styles for this group of lines
    QP.SetLineCap(capStyle);
    QP.SetLineJoin(joinStyle);
    QP.SetLineColor(lcRed, lcGreen, lcBlue);
    newPathCollection = false;
  }
  // get the path data
  QP.StartPath(px, py);
  QP.AddLineToPath(lx, ly);
  ...
  QP.SetLineWidth(lineWidth);
  QP.DrawPath(0);
  if ((x % 1000) == 999)
  {
    // 1000 lines have been drawn, start a new layer
    QP.NewLayer();

    // Set the flag so the line styles are set
    // for this group of lines
    newPathCollection = true;
  }
}
QP.CompressPage();
QP.SaveToFile(fileName);

The content stream that makes up a PDF's page description consists of fairly simple commands in a text format. Instead of using Quick PDF Library's path construction functions another option would be to build up the content stream yourself.

You can download a free copy of the PDF spec (ISO 32000-1:2008) from Adobe's website to get details of all the drawing commands (listed in section 8.5.2).

Then basically just build up a long string containing the commands that describe all your lines (or a couple of groups of strings) and use the QPL function SetPageContent to put your string into the content stream.


© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum