简体   繁体   中英

PDFlib overlap PDF with another PDF

I am generating a PDF using PDFlib where the user is able to upload images and also PDF to insert into the template.

For the image I can simply use

$image = $p->load_image("auto", $logo, "");
if ($image == 0) {
   echo ("Error: " . $p->get_errmsg());
   exit(1);
}

// Place logo in pdf
$x = 100;
$y = 100;
$p->fit_image($image, 400, 80, "");
$p->close_image($image);

I am trying to achieve the same to place a PDF.

I know I could just convert the PDF for placement to an image but that's not what I want.

How can I place the .pdf inside my PDF? Sounds crazy...

you can do this with the PDFlib Import extension PDI . Some of the bundled PDFlib samples, like invoice.php, starter_pdfmerge.php are demonstrating the usage.

// use errorpolicy exception to throw an exception instead of return 0
$p->set_option("errorpolicy=exception");
$doc = $p->open_pdi_document($logo, "");
// open page $pageno of the document
$page = $p->open_pdi_page($doc, $pageno, "");

// Place logo in pdf
$x = 100;
$y = 100;
$p->fit_pdi_page($page, 400, 80, "");
$p->close_pdi_page($page);
$p->close_pdi_document($doc);

you find further samples in the PDFlib cookbook - > PDF Import . (also as PHP)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM