Generate PDF accents with Pdflib + PHP

Asked

Viewed 180 times

1

I made the following code to pass a sequence and generates my lines in pdf with Pdflib:

função text_block ( $ p , $ text , $ xcrd , $ ycrd ) 
{ 
    $ FONT_SIZE = 24 ;   // tamanho da fonte, usada para linhas de espaço no eixo y 
    $ tmplines = explode ( "\ n" , $ text ); 
    for ( $ j = 0 ; $ j < contagem ( $ tmplines ); $ j ++) { 
      $ tmptxt = explode ( " " , $tmplines [ $j ]); 
      $str = "" ; 
      for ( $i = 0 ; $i < count ( $tmptxt ); $i ++){ 
      if ( $str == "" ) 
        $str = sprintf ( "%s" , $tmptxt [ $i ]); 
      else 
        $str = sprintf ( "%s %s" , $str , $tmptxt [ $i ]); 
      if (( strlen ( $str )* $font_size + strlen ( $tmptxt [ $i + 1 ])* $font_size )  >  1512 ){ 
        $p -> fit_textline ( $str , $xcrd , $ycrd , "" ); 
        $str = "" ; 
        $ycrd -= $font_size ; 
      } 
    } 
      $p -> fit_textline ( $str , $xcrd , $ycrd , "" ); 
      $ycrd -= $font_size ; 
  } 
    return $ycrd ; 
}

Because when I pass something like "ç" or "is" to PDF appears strange characters "Is".

How do I fix it?

UPDATE

I tried to do this but it did not work, it neither generated my pdf nor returned to my page.

$font = $p->load_font("Helvetica-Bold", "unicode", "");
$font_size=24.0;  //font size, used to space lines on y axis
$p->setfont($font, $font_size);
...
$p->fit_textline($str,$xcrd,$ycrd,"utf8");

UPDATE2

If I try to set my pdf to utf8 the code ends up crashing, but does not return error just stays forever processing.

$p = new PDFlib();
$p->set_option("stringformat=utf8");
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.