2012-04-23 3 views
1

UTF-8로 pdf를 렌더링하는 것이 가능합니다. 페르시아어 또는 아랍어 문자? 나는 tcpdf를 사용하고 싶지 않다. PHP 스크립트를 통해 pdf를 만드는 동안 성능 문제가 있습니다. 나는 PHP 5.4와 pdflib 8.0.4p2의 최신 버전을 시도 할 것이지만 나는 유효한 페르시아어 단어를 볼 수 없다.PHP PDFlib unicode

<?php 

try { 
    $p = new PDFlib(); 

    /* open new PDF file; insert a file name to create the PDF on disk */ 
    if ($p->begin_document("", "") == 0) { 
     die("Error: " . $p->get_errmsg()); 
    } 

    $p->set_info("Creator", "hello.php"); 
    $p->set_info("Author", "Rainer Schaaf"); 
    $p->set_info("Title", "Hello world (PHP)!"); 

    $p->begin_page_ext(595, 842, ""); 

    $font = $p->load_font("Courier", "unicode", ""); 

    $p->setfont($font, 24.0); 
    $p->set_text_pos(50, 700); 
    $p->show("Hello world!"); 
    $p->continue_text($p->utf8_to_utf16("(says PHP) سلام جهان", 'utf16')); 
    $p->end_page_ext(""); 

    $p->end_document(""); 

    $buf = $p->get_buffer(); 
    $len = strlen($buf); 

    header("Content-type: application/pdf"); 
    header("Content-Length: $len"); 
    header("Content-Disposition: inline; filename=hello.pdf"); 
    print $buf; 
} 
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); 
} 
$p = 0; 

답변

2

주된 문제는 Courier 글꼴에 인쇄 할 아랍어 텍스트의 글리프가없는 것입니다. Arial Unicode와 같은 글꼴을 사용하면 예상 결과가 나타납니다.

또 한가지, $p->set_parameter("textformat", "utf8");가 다음 사용할 수있는 사용 UTF8 직접 $p->continue_text("(says PHP) سلام جهان x");

에서와 같이