17.05.2014 Views

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

To fold the famous rocket looper proceed as follows:<br />

Take a sheet of paper. Fold it<br />

lengthwise in the middle.<br />

Then, fold down the upper corners. Fold the<br />

long sides inwards<br />

that the points A and B meet on the central fold.<br />

To fold the famous rocket looper proceed as follows: Take a sheet of<br />

paper. Fold it lengthwise in the middle. Then, fold down the upper<br />

corners. Fold the long sides inwards that the points A and B meet on<br />

the central fold.<br />

Fig. 8.20<br />

Top: text with redundant line<br />

breaks<br />

Bottom: replacing the linebreaks<br />

with the charmapping option<br />

charmapping={linefeed {linefeed -1}}<br />

Each sequence of CRLF combinations will be replaced with a single space:<br />

charmapping={CRLF {space -1}}<br />

We will take a closer look at the last example. Let’s assume you receive text where the<br />

lines have been separated with fixed line breaks by some other software, and therefore<br />

cannot be properly formatted. You want to replace the linebreaks with space characters<br />

in order to achieve proper formatting within the fitbox. To achieve this we replace arbitrarily<br />

long sequences of linebreaks with a single space character. The initial text looks<br />

as follows:<br />

To fold the famous rocket looper proceed as follows:<br />

Take a sheet of paper. Fold it<br />

lengthwise in the middle.<br />

Then, fold down the upper corners. Fold the<br />

long sides inwards<br />

that the points A and B meet on the central fold.<br />

The following code fragment demonstrates how to replace the redundant linebreak<br />

characters and format the resulting text:<br />

/* assemble option list */<br />

String optlist =<br />

"fontname=Helvetica fontsize=9 encoding=winansi alignment=justify " +<br />

"charmapping {CRLF {space -1}}"<br />

/* place textflow in fitbox */<br />

textflow = p.add_textflow(-1, text, optlist);<br />

if (textflow == -1)<br />

throw new Exception("Error: " + p.get_errmsg());<br />

result = p.fit_textflow(textflow, left_x, left_y, right_x, right_y, "");<br />

if (!result.equals("_stop"))<br />

{ /* ... */ }<br />

p.delete_textflow(textflow);<br />

Figure 8.20 shows Textflow output with the unmodified text and the improved version<br />

with the charmapping option.<br />

8.2 Multi-Line Textflows 217

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!