I did the following code to pass a string, and it generates my strings in pdf format:
function text_block($p,$text,$xcrd,$ycrd)
{
$font_size=24;
$tmplines = explode("\n",$text);
for($j=0;$j<count($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 transfer something like "é" or "ç" to the PDF, the strange characters "Ã ©" appear.
How to fix it?
Exemple
Will something generate pdf with accents?
$p = new PDFlib();
$p->set_option("stringformat=utf8");
$name_file = "wp-content/uploads/".$current_user->ID."_".$time."_mysite.pdf";
if ($p->begin_document($name_file, "") == 0) {
die("Error: " . $p->get_errmsg());
}
$p->set_info("Creator", "mysyte.com.br");
$p->set_info("Author", $current_user->username);
$p->set_info("Title", "title");
$y = 2138;
$x = 1512;
$p->begin_page_ext($x, $y, "");
$y -= 100;
$y = text_block($p, "A data é: ".date("d/m/Y", $time), 50, $y);
$p->end_page_ext("");
$p->end_document("");
something like "Data é: 03/23/2016" should have appeared in pdf format, but when I add bla stretch, it hangs in php and does not return an error or does not create a PDF, ne does nothing. I don’t know if you need to install something, or some kind of configuration, or you have to enable something.
LINK
" 10-6. " , , .php, , pdflib.upr, pdf_set_parameter.
, , :
pdf_continue_text($p,"$f (".chr(128)." Ç à á â ã ç è é ê)");
, fuction fit_textline
UPDATE
.
try {
$p = new PDFlib();
if ($p->begin_document("wp-content/uploads/hello.pdf", "") == 0) {
die("Error: " . $p->get_errmsg());
}
$p->set_info("Creator","hello.php");
$p->set_info("Author","Rasmus Lerdorf");
$p->set_info("Title","Hello world (PHP)");
$p->set_parameter("FontOutline", "Ubuntu=/var/www/html/wordpress/wp-includes/fonts/ubuntu-font-family/Ubuntu-C.ttf");
$p->set_parameter("textformat", "utf8");
$y = 2138;
$x = 1512;
$p->begin_page_ext($x, $y, "");
$p->set_text_pos(25,750);
$font = $p->findfont("Ubuntu", "unicode", "");
$font_size=24.0;
$p->setfont($font, $font_size);
$p->continue_text("(".chr(128)." Ç à á â ã ç è é ê)");
$p->end_page_ext("");
$p->end_document("");
}catch (\PDFlibException $e) {
die("PDFlib exception occurred in hello sample:\n" .
"[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
$e->get_errmsg() . "\n");
}catch (\Exception $e) {
die($e);
}
pdf , - 500 , , try catch.
-, PDFlib, , ? utf8, .. ç?