Q: I would like to build upon text2pdf sample (from Files section in
PDFNet KB) to implement text layout for more complex text styles. I
plan to build on the code in element builder that lays out a paragraph
of one size font one font face. but will add support for multiple
fonts on one line and more than one height on the same line.
To implement this I need to know if the following code is OK. In
otherwords, will the PDF have extraneous text in it?
Notice that there are sucessive CreateTextRun statements and only the
last element is written to the PDF.
The first three text run's are abandoned, but do not actually get into
the final PDF??
Example:
//Set up the text run here
theFont = pdftron.PDF.Font.CreateTrueTypeFont
(......................
element = theElementBuilder.CreateTextBegin
(...........................
theElementWriter.WriteElement(element);
element.SetTextMatrix(.......................
theElementWriter.WriteElement(element);
//Make four CreateTextRun statements, abandoning the first three
element = theElementBuilder.CreateTextRun("the");
lengthOfTextString = element.GetTextLength();
element = theElementBuilder.CreateTextRun("the last ");
lengthOfTextString = element.GetTextLength();
element = theElementBuilder.CreateTextRun("the last under ");
lengthOfTextString = element.GetTextLength();
element = theElementBuilder.CreateTextRun("the last under the
");
lengthOfTextString = element.GetTextLength();
theElementWriter.WriteElement(element);
theElementWriter.WriteElement(theElementBuilder.CreateTextEnd
());
------
A: Your code is ok. Only the last text run that is written on the page
will be actually saved to PDF. There is no memory in repeatedly
creating and discarding elements using ElementBuilder. You can use
this feature in order to calculate the size of every text run before
is placed on the page.