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 < 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 <
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.
CodePudding user response:
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:
- You can specify the
<
character as a character reference. For this the optioncharref=true
must be set and you specify in the text<
. - You use another character as start or end textflow character and define
begoptlistchar
andendoptlistchar
- You do not use inline options, then you can use one or more
add_textflow()
calls to assemble the textflow handle.
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.