我有一个表格,人们可以上传pdf
使用fpdf,我附加这些pdf并生成一个新的。这对现在的肖像来说还不错。如果有人上传了一个肖像格式的pdf,我被剪掉了,因为它不适合肖像a4文档。有没有办法确定pdf的对齐方式?这是我要附加的代码:
/* APPEND PDFs */
$files = [];
array_push($files, $upload_folder . '/' . $pdf_name);
if($new_path != 0 & $ext == 'pdf'){
array_push($files, $new_path);
}
if($new_path1 != 0 & $ext1 == 'pdf'){
array_push($files, $new_path1);
}
if($new_path2 != 0 & $ext2 == 'pdf'){
array_push($files, $new_path2);
}
if($new_path3 != 0 & $ext3 == 'pdf'){
array_push($files, $new_path3);
}
if($new_path4 != 0 & $ext4 == 'pdf'){
array_push($files, $new_path4);
}
if($new_path5 != 0 & $ext5 == 'pdf'){
array_push($files, $new_path5);
}
if($new_path6 != 0 & $ext6 == 'pdf'){
array_push($files, $new_path6);
}
pdf = new \setasign\Fpdi\Fpdi();
// iterate over array of files and merge
foreach ($files as $file) {
$pageCount = $pdf->setSourceFile($file);
for ($i = 0; $i < $pageCount; $i++) {
$tpl = $pdf->importPage($i + 1, '/MediaBox');
$pdf->addPage();
$pdf->useTemplate($tpl);
}
}
// output the pdf as a file (http://www.fpdf.org/en/doc/output.htm)
$pdf->Output('F',$upload_folder . '/' . $pdf_name);非常感谢
发布于 2021-12-03 11:20:17
多亏了KIKO Software,我能够用这个例子解决这个问题:
// iterate through the files
foreach ($files AS $file) {
// get the page count
$pageCount = $pdf->setSourceFile($file);
// iterate through all pages
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
// import a page
$templateId = $pdf->importPage($pageNo);
// get the size of the imported page
$size = $pdf->getTemplateSize($templateId);
// add a page with the same orientation and size
$pdf->AddPage($size['orientation'], $size);
// use the imported page
$pdf->useTemplate($templateId);
$pdf->SetFont('Helvetica');
$pdf->SetXY(5, 5);
$pdf->Write(8, 'A simple concatenation demo with FPDI');
}
}https://stackoverflow.com/questions/70213143
复制相似问题