Example #1
0
PDF_set_info($p, "Title", "PDFlib block processing sample (PHP)");
$blockcontainer = PDF_open_pdi($p, $infile, "", 0);
if ($blockcontainer == 0) {
    die("Error: " . PDF_get_errmsg($p));
}
$page = PDF_open_pdi_page($p, $blockcontainer, 1, "");
if ($page == 0) {
    die("Error: " . PDF_get_errmsg($p));
}
PDF_begin_page($p, 20, 20);
/* dummy page size */
/* This will adjust the page size to the block container's size. */
PDF_fit_pdi_page($p, $page, 0, 0, "adjustpage");
/* Fill all text blocks with dynamic data */
foreach ($data as $key => $value) {
    if (PDF_fill_textblock($p, $page, $key, $value, "embedding encoding=winansi") == 0) {
        printf("Warning: %s\n ", PDF_get_errmsg($p));
    }
}
PDF_end_page($p);
/* close page */
PDF_close_pdi_page($p, $page);
PDF_close($p);
/* close PDF document */
PDF_close_pdi($p, $blockcontainer);
$buf = PDF_get_buffer($p);
$len = strlen($buf);
header("Content-type: application/pdf");
header("Content-Length: {$len}");
header("Content-Disposition: inline; filename=businesscard.pdf");
print $buf;
Example #2
0
 function writeBlock()
 {
     // テンプレートを使用する
     if (!file_exists($this->pdfpath)) {
         return;
     }
     // 既存PDFのドキュメントを取得
     $doc = pdf_open_pdi($this->pdf, $this->pdfpath, NULL, 0);
     // 既存PDFのドキュメントから指定ページを取得
     $page = pdf_open_pdi_page($this->pdf, $doc, 1, NULL);
     // ページを開く
     $this->openPage();
     // 既存PDFのページを割り当てる
     PDF_fit_pdi_page($this->pdf, $page, 0, 0, "adjustpage");
     // テキストブロックの書き込み
     $max = count($this->arrText);
     for ($i = 0; $i < $max; $i++) {
         foreach ($this->arrText[$i] as $key => $val) {
             if ($val != "") {
                 // 文字コードの変換
                 mb_convert_variables($this->dst_code, $this->src_code, $val);
                 // 書き込み
                 $ret = PDF_fill_textblock($this->pdf, $page, $key, $val, $this->block_option);
             }
         }
     }
     // イメージブロックの書き込み
     $max = count($this->arrImage);
     for ($i = 0; $i < $max; $i++) {
         foreach ($this->arrImage[$i] as $key => $val) {
             if ($val != "") {
                 $img = PDF_load_image($this->pdf, "auto", $val, NULL);
                 $ret = PDF_fill_imageblock($this->pdf, $page, $key, $img, NULL);
             }
         }
     }
     // 割り当てたページを閉じる
     PDF_close_pdi_page($this->pdf, $page);
     // 割り当てたドキュメントを閉じる
     PDF_close_pdi($this->pdf, $doc);
 }