0

I'm currently using TCPDI merge four documents into a single PDF and temporarily storing the document using a variable. Is it possible to add "Bates Numbering" to the file, starting with the third page? (The first two pages are a cover letter.) Thanks in advance for pointing me in the right direction

    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");
mike437
  • 77
  • 1
  • 8

1 Answers1

1

I'm not familiar with Bates System but what i did was add the Page number as a Label and check your PageNo variable/index to determine when to show your batesNo.

For the labeling. See the TCPDF documentation.

*Code not tested

    <?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);
        }
        }



    ?>
Oluwaseye
  • 685
  • 8
  • 20