Some questions on efficient PDF generation using PDFNet.

Q: I have three questions. First, how do I get the library to use the
(string)'
text display operator rather than the T* (string) Tj operator?

Second, I need to generate 22 equally spaced greenbars as a background
on a page. I need a high-performance way of doing this. Do you have
any suggestions?

Right now I'm using the following code (I develop with C++):

        // Conjure up the greenbar pattern. Maybe this should be a jpg
or something else?
        if (xmlcon.pageConfig.green_bar)
        {
            GState gs;
            greenBarElement = eb.CreateRect(0, 0, POINTS_PER_INCH *
xmlcon.pageConfig.page_width, POINTS_PER_INCH *
xmlcon.pageConfig.page_height);
            // Set the fill color space to the Pattern color space.
            gs = greenBarElement.GetGState();
            gs.SetFillColorSpace(ColorSpace::CreatePattern());
            gs.SetFillColor(CreateGreenbarPattern(doc,
xmlcon.pageConfig.red, xmlcon.pageConfig.green,
xmlcon.pageConfig.blue));
            greenBarElement.SetPathFill(true);
              writer.WriteElement(greenBarElement);
                  eb.Reset(); // Reset the GState to
default
        }

//--------------------------------------------------------------------------
-
Obj CreateGreenbarPattern(PDFDoc &doc, int red, int green, int blue) {
       ElementWriter writer;
       ElementBuilder eb;

       // Create a new pattern content stream - a greenbar.
------------
       writer.Begin(doc);
       eb.PathBegin();
        eb.CreateRect(0, 0, 500, 500);
       Element greenbar = eb.PathEnd();
       greenbar.SetPathFill(true);

greenbar.GetGState().SetFillColorSpace(ColorSpace::CreateDeviceRGB());
       greenbar.GetGState().SetFillColor(ColorPt(red/255.0, green/
255.0, blue/255.0));
       writer.WriteElement(greenbar);

       Obj pattern_dict = writer.End();

       // Initialize pattern dictionary. For details on what each
parameter represents please
       // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF
Reference Manual.
       pattern_dict.PutName("Type", "Pattern");
       pattern_dict.PutNumber("PatternType", 1);

       // TilingType - Constant spacing.
       pattern_dict.PutNumber("TilingType", 1);

       // This is a Type1 pattern - A colored tiling pattern.
       pattern_dict.PutNumber("PaintType", 1);

       // Set bounding box
       pattern_dict.PutRect("BBox", 0, 0, 200, 1000);

       // Create and set the matrix
       Common::Matrix2D pattern_mtx(0.075, 0, 0, 0.075, 0, 0); //
Number of green lines
       pattern_dict.PutMatrix("Matrix", pattern_mtx);

       // Set the desired horizontal and vertical spacing between
pattern cells,
       // measured in the pattern coordinate system.
       pattern_dict.PutNumber("XStep", 200);
       pattern_dict.PutNumber("YStep", 1000);

       return pattern_dict; // finished creating the Pattern
resource }

The third question I have is, what is the absolute fastest way to
write a string to a page?

This is the loop I'm currently using to write a series of strings to a
page:

            for (i = 0; i < sheet->lineCount; i++)
            {
                writer.WriteElement(eb.CreateTextNewLine()); // New
line.
BUG?? Can't use (<string>)'
                element = eb.CreateTextRun(&sheet->lines[i][0]);
                writer.WriteElement(element);
            }

----
A:

do I get the library to use the (string)' text display operator rather than
the T* (string) Tj operator?

"(string)'" is equivalent to "T* (string) Tj" and using ElementWriter
interface there is no option to control which form is written out. If
you need this type of control, you could use
elementwriter.WriteString(..)/WriteBuffer(..) method to out content
operators directly. Unless it is absolutely necessary, I would not
recommend using these low-level features.

In case you concerned about file size issues, PDFNet is compressing
all content streams using Flate (ZIP) compression and this type of
repeat text pattern is best suited for deflate algorithm. As a result,
even for 500,000 lines of text you will see a barely noticeable
difference in file size.

I need to generate 22 equally spaced greenbars as a background on a page.
I need a high-performance way of doing this.

Your approach (of creating pattern) is quite good. Since you are
creating only 22 rectangles you may also want to output these
rectangles directly on the page - in a form of a single path object.
For example:

...
eb.PathBegin();
// for (i=0 to 22) ?
eb.Rect(..rect1..);
eb.Rect(..rect2..);
...
eb.Rect(..rect22..);
greenBarElement = eb.PathEnd();
gs = greenBarElement.GetGState();
gs.SetFillColorSpace(ColorSpace::CreateDeviceRGB());
gs.SetFillColor(ColorPt(red/255.0, green/255.0, blue/255.0));
greenBarElement.SetPathFill(true);
writer.WriteElement(greenBarElement);
...

This is probably the fastest way to process data (for both PDF
consumers and producers), but I doubt that you will see any
performance issue with the pattern approach.

The third question I have is, what is the absolute fastest way to
write a string to a page?

The approach you are currently using is very fast. It is true that
"(string)'" is a bit shorter than "T* (string) Tj" string, however in
terms of actual benchmarks there is no significant difference in the
time required to output these strings.