使用 FPDF 复制文本并设置页面大小

Pau*_*ert 0 php fpdf

我正在使用 FPDF。该类以其最基本的形式实现和工作。我创建了一张名片 (3.5" x 2") 并将其放在 8.5" x 11" 的页面上。卡片在单页上复制 10 次。

这是我想要做的:

  1. 复制一个变量 10 次并为每个变量定义一个自定义偏移量(每张卡片底部打印字符串)

  2. 将页面大小从 更改$unit='mm', $size='A4'$unit='inch', $size='letter'。这样做会给我一个错误FPDF error: Incorrect unit: inch

我正在使用的代码如下:

       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;
Run Code Online (Sandbox Code Playgroud)

我读过的文档似乎非常有限。如果您知道任何好的文档,请告诉我。谢谢。

Pau*_*ert 5

如果其他人遇到同样的问题,这里是我问题第二部分的答案:

您必须在此处设置页面大小...

$pdf->AddPage('P', 'Letter');
Run Code Online (Sandbox Code Playgroud)

这将页面定义为 "Portrait" , "Letter"

我仍在寻找第一部分的答案。如果有人可以提供帮助,我将不胜感激。