昨日の続きです。
Image_Barcode2で作ったバーコードをPDFに貼り付けたい。
この案件ではPDF作成にPDFlibを使っています。
// $this->pdflib はPDFlibオブジェクト
protected function pdf_set_barcode($jancode, $x, $y, $opt='')
{
$barcode_height = 30;
$barcode_width = 1;
$barcode_with_num = true;
$pvf_filename = $jancode;
ob_start();
$gd = Image_Barcode2::draw($jancode, 'ean13', 'png', false, $barcode_height, $barcode_width, $barcode_with_num);
imagepng($gd, null);
imagedestroy($gd);
$this->pdflib->create_pvf($pvf_filename, ob_get_clean(), "");
$barcode_image = $this->pdflib->load_image('png', $pvf_filename, '');
$this->pdflib->fit_image($barcode_image, $x, $y, $opt);
$this->pdflib->close_image($barcode_image);
$this->pdflib->delete_pvf($pvf_filename);
}
// $this->pdflib はPDFlibオブジェクト
protected function pdf_set_barcode($jancode, $x, $y, $opt='')
{
$barcode_height = 30;
$barcode_width = 1;
$barcode_with_num = true;
$pvf_filename = $jancode;
ob_start();
$gd = Image_Barcode2::draw($jancode, 'ean13', 'png', false, $barcode_height, $barcode_width, $barcode_with_num);
imagepng($gd, null);
imagedestroy($gd);
$this->pdflib->create_pvf($pvf_filename, ob_get_clean(), "");
$barcode_image = $this->pdflib->load_image('png', $pvf_filename, '');
$this->pdflib->fit_image($barcode_image, $x, $y, $opt);
$this->pdflib->close_image($barcode_image);
$this->pdflib->delete_pvf($pvf_filename);
}
// $this->pdflib はPDFlibオブジェクト protected function pdf_set_barcode($jancode, $x, $y, $opt='') { $barcode_height = 30; $barcode_width = 1; $barcode_with_num = true; $pvf_filename = $jancode; ob_start(); $gd = Image_Barcode2::draw($jancode, 'ean13', 'png', false, $barcode_height, $barcode_width, $barcode_with_num); imagepng($gd, null); imagedestroy($gd); $this->pdflib->create_pvf($pvf_filename, ob_get_clean(), ""); $barcode_image = $this->pdflib->load_image('png', $pvf_filename, ''); $this->pdflib->fit_image($barcode_image, $x, $y, $opt); $this->pdflib->close_image($barcode_image); $this->pdflib->delete_pvf($pvf_filename); }
load_imageがファイルを要求しているんだけどいちいちtmpファイル保存するのもなんか気持ち悪いな、って思っていたところ、pvf(PDFlib Virtual file)というのがあったのでそれを使っています。
GDの出力データをob_使わずに取得する方法ないのかな…