【问题标题】:php append pdf to pdf and check the page template firstphp将pdf附加到pdf并首先检查页面模板
【发布时间】:2021-12-03 10:52:29
【问题描述】:

我有一个表格供人们上传 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);

非常感谢

【问题讨论】:

  • 那么什么是“垂直对齐的pdf”?它是否是文本的任何部分“垂直对齐”的 PDF?这意味着什么?也许一个例子可以说明这一点。当“它不起作用”时会发生什么?
  • 对不起,当然。我的意思是页面的对齐方式。纵向与横向。 pdf 格式为“横向”或“纵向”。它没有混合。
  • 当我现在上传横向页面时,它被截断了,因为它不适合纵向页面
  • 好的,这完全澄清了它。谢谢你。也许您应该编辑您的问题以使其清楚。人们首先阅读您的问题,有些人永远不会到达 cmets。
  • 哦,然后this example 向您展示了如何根据源文件重新定向页面。您的$pdf-&gt;addPage() 相当空。

标签: php pdf


【解决方案1】:

感谢 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');
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 2016-01-29
    • 2021-10-30
    • 2010-12-09
    相关资源
    最近更新 更多