使用FPDF生成正在打印的PDF。 (THIS插件的一部分)
生成的PDF的背景总是白色的,我需要透明才能打印到白色以外的背景颜色的项目。
可以使用FPDF完成吗?
以下是用于生成PDF的代码。
public function executeExportPdf()
{
$content_images = $this->getParameter("content_images");
if (!is_array($content_images) || !count($content_images)) {
echo json_encode(array('status' => 'error'));
exit();
}
$height = intval($this->getParameter('height'));
$width = intval($this->getParameter('width'));
$dpi = intval($this->getParameter('dpi'));
if (!$height || !$width || !$dpi) {
echo json_encode(array('status' => 'The pdf options is not valid'));
exit();
}
$orientation = $height > $width ? 'P' : 'L';
$PDF = new FPDF($orientation, 'mm', array($height, $width));
$color_scheme = $this->getParameter('color_scheme') == '1' ? 'cmyk' : 'rgb';
foreach ($content_images as $content_image) {
if ($color_scheme == 'cmyk') {
if (class_exists("Imagick")) {
$content_image = substr($content_image, 23); // remove "data:image/jpeg;base64," - text
$imagick = new Imagick();
$imagick->readImageBlob(base64_decode($content_image));
$imagick->transformImageColorspace(Imagick::COLORSPACE_CMYK);
$content_image = 'data:image/jpeg;base64,' . base64_encode($imagick->getImageBlob());
}
}
$PDF->AddPage();
$PDF->Image($content_image, 0, 0, -$dpi , -$dpi, 'JPG');
}
$PDF->Output("order-{$this->getParameter('order', 0)}.pdf", 'D');
die();
}