phppdfmacrospdflib

PDFlib PHP macros and inline optlists


I want to use macros and inline optlists within my PDFlib Script and it seems to work, but as soon as there is a "<" symbol in the text source, I get an error from PDFlib which says there is an undefined macro.

Let's say we have the following text: $text = '<font='.$fontBold.'>Lorem ipsum<font='.$fontRegular.'> dolor sit amet &lt; 0,11m²';
If I do this everything works fine and the text will be displayed as this: "Lorem Ipsum dolor sit amet < 0,11m²"

But as soon as I change &lt; to the according symbol "<", I get the error Unknown option '0,11' in ... because PDFlib thinks a new macro is defined there.

Is there any way to avoid this? Because obviously I don't want "<" in my text.


Solution

  • that is actually quite simple:

    the < character is by default the start character for an inline option in create_textflow. If you now want to output these characters as text, this naturally leads to a conflict, which you could solve as follows:

    Please refer to the PDFlib Tutorial, chapter 9.2.2 "9.2.3 Inline Option Lists and Macros":

    The characters for bracketing option lists can be redefined with the begoptlistchar and endoptlistchar options. Supplying the keyword none for the begoptlistchar option completely disables the search for option lists. This is useful if the text doesn’t contain any inline option lists, and you want to make sure that »<« and »>« will be processed as regular characters.