【问题标题】:Working on putting a image on to a multi Page pdf document致力于将图像放在多页 pdf 文档上
【发布时间】:2016-06-13 19:52:10
【问题描述】:

我一直在使用以下代码将图像标记放在多页 pdf 文档的单页上。我遇到的问题是,如果我将页面设置为第 5 页,它将不会保存 PDF 的其余部分,如果我将其设为它工作的最后一页,我希望能够选择文档中的任何页面。 下面是我的代码

  <?php

  require_once('fpdf/fpdf.php');
  require_once('fpdi/fpdi.php');
$pdf = new FPDI();
$fullPathToPDF = 'scann/Mackay/my.pdf';

$pdf->setSourceFile($fullPathToPDF);
//echo $pageCount;

for ($i = $t; $i <= $pageCount; $i++) {
    $pdf->importPage($t);
    $pdf->AddPage();
    $pdf->useTemplate($t);
}
//puting the stamp onto the page 
$pdf->Image('Posted.png', 100, 120, 0, 0, 'png');
//save the file 
$pdf->Output($fullPathToPDF, 'F');
?>

【问题讨论】:

    标签: php fpdf fpdi


    【解决方案1】:

    在循环遍历 for 循环中的所有源文件页面时,您需要插入图像:

    require_once('fpdf/fpdf.php');
    require_once('fpdi/fpdi.php');
    $pdf = new FPDI();
    $fullPathToPDF = 'scann/Mackay/my.pdf';
    
    $pageCount = $pdf->setSourceFile($fullPathToPDF);
    //echo $pageCount;
    
    for ($i = 1; $i <= $pageCount; $i++) {
        $pdf->importPage($i);
        $pdf->AddPage();
        $pdf->useTemplate($i);
    
        if($i == 5){
            //puting the stamp onto the page 
            $pdf->Image('Posted.png', 100, 120, 0, 0, 'png');
        }
    }
    
    //save the file 
    $pdf->Output($fullPathToPDF, 'F');
    ?>
    

    【讨论】:

      【解决方案2】:

      Wades 解决方案对我不起作用,我认为最新版本的 FPDI 改变了一些处理方式。我必须将 $pdf->importPage($i) 分配给一个新变量并将其传递给 useTemplate 以使其工作。

      for ($i = 1; $i <= $pageCount; $i++) {
          $pdf->AddPage();
          $imported = $pdf->importPage($i);
          $pdf->useTemplate($imported);
      
          if($i == 5){
              //puting the stamp onto the page 
              $pdf->Image('Posted.png', 100, 120, 0, 0, 'png');
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2013-06-27
        • 2011-02-24
        • 2012-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-14
        • 1970-01-01
        • 2012-10-10
        相关资源
        最近更新 更多