1

I'm placing a textflow with UTF-16 text in PHP (PDF_create_textflow,PDF_fit_textflow) which works fine.

How do I get justified Text "" without seeing the BOM sign (Up Arrow) in the Document?

Any other way I could style text justified rather than with inline option alignment?

$compo_txt = html_entity_decode($compo_txt, ENT_QUOTES, 'UTF-8');
$compo_txt = "<alignment=justify>".$compo_txt;
$compo_txt = iconv("UTF-8", "UTF-16", $compo_txt);
$len = strlen($compo_txt);
$compo_flow = PDF_create_textflow($p, $compo_txt, "fontname=arial fontsize=".$compo_size." encoding=unicode textlen=" . $len . " embedding=true");


$flow_warning = PDF_fit_textflow(
    $p, $compo_flow, $compo_x + $compo_w, 
    $compo_y, $compo_x, $compo_y - $compo_h,
    'orientate=' . $compo_o
);

2 Answers2

1

Using alignment in optlist not as inline otption did the job:

PDF_create_textflow($p, $compo_txt, "fontname=arial fontsize=".$compo_size." encoding=unicode textlen=" . $len . " embedding=true alignment=justify");
0

alignment work of course as inline option, but due to the used textlen option, this will not work in your case.

Textlen is explained in the PDFlib 9.2.0 API reference with the following words:

(Integer or keyword; required for text fragments with fixedtextformat=false and textformat=utf16xx in non-Unicode aware languages) Number of bytes or (in Unicode-capable languages) characters before the next inline option list (see »Inline option lists for Textflows«, page 103).

(I added the bold highlighting)

As you specify as textlen the length of the complete textstring, no inline option will be processed.

The main question: Why do you use textformat=utf16? Why not just use textformat=utf8 (or stringformat=utf8) if you already have utf8 strings? And you can also use option charref, so that character references are processed.

When you set stringformat=utf8 and charref=true (see PDFlib 9.2 Tutorial, chapter "5.2.2 Language Bindings with UTF-8 Support") you can use the simplify your code:

PDF_set_option($p, "stringformat=utf8 charref=true");

$compo_txt = "<alignment=justify>".$compo_txt;
$compo_flow = PDF_create_textflow($p, $compo_txt, "fontname=arial fontsize=".$compo_size." encoding=unicode embedding=true");


$flow_warning = PDF_fit_textflow(
    $p, $compo_flow, $compo_x + $compo_w, 
    $compo_y, $compo_x, $compo_y - $compo_h,
    'orientate=' . $compo_o
);
Rainer
  • 2,013
  • 1
  • 10
  • 7