首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php将pdf附加到pdf并首先检查页面模板

php将pdf附加到pdf并首先检查页面模板
EN

Stack Overflow用户
提问于 2021-12-03 10:52:29
回答 1查看 12关注 0票数 1

我有一个表格,人们可以上传pdf

使用fpdf,我附加这些pdf并生成一个新的。这对现在的肖像来说还不错。如果有人上传了一个肖像格式的pdf,我被剪掉了,因为它不适合肖像a4文档。有没有办法确定pdf的对齐方式?这是我要附加的代码:

代码语言:javascript
复制
/* 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);

非常感谢

EN

回答 1

Stack Overflow用户

发布于 2021-12-03 11:20:17

多亏了KIKO Software,我能够用这个例子解决这个问题:

代码语言:javascript
复制
// 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');
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70213143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档