首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TCPDF -在合并的PDF中添加"Bates Numbering“

TCPDF -在合并的PDF中添加"Bates Numbering“
EN

Stack Overflow用户
提问于 2018-08-01 21:29:46
回答 1查看 141关注 0票数 0

我目前正在使用TCPDI,将四个文档合并到一个PDF中,并使用一个变量临时存储文档。是否可以在文件中添加“贝茨编号”,从第三页开始?(前两页是求职信。)提前感谢你为我指明了正确的方向

代码语言:javascript
复制
    require_once('../tcpdf/tcpdf.php');
    require_once('../tcpdf/tcpdi.php');

    // Create new PDF document.
    $pdf = new TCPDI();

    // iterate through the files
    foreach ($filesarray 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);

    // Set page boxes from imported page 1.
    $pdf->setPageFormatFromTemplatePage($pageNo, $size['orientation']);

    // use the imported page
    $pdf->useTemplate($templateId);
    }
    }

    // Output the new PDF
    $attachment = $pdf->Output("Merged.pdf", "S");
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-01 21:52:52

我不熟悉贝茨系统,但我所做的是添加页面编号作为标签,并检查PageNo变量/索引以确定何时显示batesNo。

为了贴标签。请参阅TCPDF文档。

*代码未测试

代码语言:javascript
复制
    <?php


     // iterate through the files
        foreach ($filesarray AS $file) {
        // get the page count
        $pageCount = $pdf->setSourceFile($file);

          $batesNo = 0000000001; //initialize*****

        // 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);

             /***********NEW BLOCK*******/
          if ($pageNo > 3) { 
           $pdf->SetTitle('JonesNo-'.$batesNo);
            } else { 
              $pdf->SetTitle($pageNo); 
           }       
////////////////////////

 // add a page with the same orientation and size
        $pdf->AddPage($size['orientation'], $size);

        // Set page boxes from imported page 1.
        $pdf->setPageFormatFromTemplatePage($pageNo, $size['orientation']);

        // use the imported page
        $pdf->useTemplate($templateId);
        }
        }



    ?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51642519

复制
相关文章

相似问题

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