Created
November 13, 2015 12:39
-
-
Save hiddebraun/908de435e6677306435b to your computer and use it in GitHub Desktop.
Fit existing small PDF to A4 with PDFLib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$outfile = ""; | |
$p = new PDFLib(); | |
if ($p->begin_document($outfile, "") == 0) | |
throw new Exception("Error: " . $p->get_errmsg()); | |
$indoc = $p->open_pdi_document('label.pdf',''); | |
if ($indoc == 0) | |
throw new Exception("Error: " . $p->get_errmsg($p)); | |
$page = $p->open_pdi_page($indoc, 1, ""); | |
/* Start an A4 output page (210mm x 297mm) */ | |
$p->begin_page_ext(842, 595, ""); | |
/* Place the imported page without any scaling */ | |
$p->fit_pdi_page($page, 0, 0, "boxsize={842 595} fitmethod=meet"); | |
$p->end_page_ext(""); | |
$p->close_pdi_page($page); | |
$p->end_document(""); | |
$buf = $p->get_buffer(); | |
$len = strlen($buf); | |
file_put_contents('out.pdf', $buf);cd | |
$p = 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment