Paul Dessert
Paul Dessert

Reputation: 6389

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.

Upvotes: 0

Views: 10556

Answers (3)

Michael Stoegner
Michael Stoegner

Reputation: 11

There is this undocumented function in the class FPDF also called FPDF.

function FPDF($orientation='P', $unit='mm', $size='A4') { ... }

I used it this way (– please note that the $pdf object is a child class of FPDF class. This could, for instance, be an FPDI object; When it is defined as an FPDI object, it is defined in the same way as in your original question, where $pdf is an FPDI object):

$pdf = new FPDI(); 
$pdf->FPDF('L' /* =$orientation */, 'pt' /* =$unit */, 'A4' /* =$size */);

So, in this code example an object of a class that is derived from the FPDF class is calling the FPDF function of the FPDF class to set the orientation of the PDF document and sets the unit to 'pt' (= points) and the size to DIN A4, which is the standard letter format in Germany.

Upvotes: 1

user3096714
user3096714

Reputation: 1

You do it where you initiate the constructor, where you currently have $pdf = new FPDI()

$pdf = new FPDF('P', 'in', 'Letter');

P - sets the document up as portrait in - sets the unit up as inches Letter - sets the document size as US Letter

http://www.fpdf.org/en/doc/fpdf.htm

Upvotes: 0

Paul Dessert
Paul Dessert

Reputation: 6389

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.

Upvotes: 5

Related Questions