Search code examples
phpfpdf

Replicating text with FPDF and setting page size


I'm using FPDF. The class is implemented and working in its most basic form. I created a business card (3.5" x 2") and placed it on an 8.5" x 11" page. The card is replicated 10 times on a single page.

Here is what I'm trying to do:

  1. Replicate a variable 10 times and define a custom offset for each (string prints at the bottom of each card)

  2. Change the page size from $unit='mm', $size='A4' to $unit='inch', $size='letter'. Doing so gives me an error FPDF error: Incorrect unit: inch

The code I'm working with is below:

       switch($_POST['picker']){
        case 'option1':
           // initiate FPDI 
            $pdf = new FPDI(); 
            // add a page 
            $pdf->AddPage(); 
            // set the sourcefile 
            $pdf->setSourceFile('10-up.pdf'); 
            // import page 1 
            $tplIdx = $pdf->importPage(1); 
            // use the imported page and place it at point 10,10 with a width of 100 mm 
            $pdf->useTemplate($tplIdx, 0, 0, 216, 279); 
            // now write some text above the imported page 
            $pdf->SetFont('Arial'); 
            $pdf->SetTextColor(0,0,0); 
            $pdf->SetXY(12, 12); 

             //This is the variable I want to repeat 10 times and define custom offsets for each
            $pdf->Write(0, $user); 
            $pdf->Output('final.pdf', 'D'); 
           break;

The documentation I've read seems really limited. If you know of any good documentation, please let me know. Thanks.


Solution

  • In case anyone else is having the same problem, here is the answer for the second part of my question:

    You have to set the page size here...

    $pdf->AddPage('P', 'Letter');
    

    This defines the page as "Portrait" , "Letter"

    I'm still looking for an answer on part one. If anyone can help, I'd appreciate it.