【问题标题】:edit existing pdf footer using fpdi and fpdf使用 fpdi 和 fpdf 编辑现有的 pdf 页脚
【发布时间】:2016-10-20 07:04:30
【问题描述】:

我有大量的 pdf。每个 pdf 包含许多页面。我必须在现有 pdf 的每一页中添加页脚。

  1. 导入文件后怎么知道pdf有多少页?
  2. 我可以创建一个在每个页面上自动调用的函数吗?

现在请建议如何拒绝。文件中的页面数以及如何循环它们并在每页上添加页脚?

【问题讨论】:

    标签: fpdf fpdi


    【解决方案1】:
    $pdf = new FPDI();
    $filename="Path to the file";
    // get the page count
    $pageCount = $pdf->setSourceFile($filename);
    // 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);
    
        // create a page (landscape or portrait depending on the imported page size)
        if ($size['w'] > $size['h']) {
            $pdf->AddPage('L', array($size['w'], $size['h']));
        } else {
            $pdf->AddPage('P', array($size['w'], $size['h']));
        }
    
        // use the imported page
        $pdf->useTemplate($templateId);
    
        $pdf->SetFont('Helvetica');
        $pdf->SetFontSize(8);
        $pdf->SetXY(5,0);
        $pdf->Write(5, "CSM ROLL NO - $roll_no");
    }
    
    // Output the new PDF
    $pdf->Output("targetpath",'F');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 1970-01-01
      • 1970-01-01
      • 2011-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多