首页 文章

FPDF不在所有页面上书写

提问于
浏览
1

嗨我正在使用FPDF和FPDI,我正在使用FPDI连接几个PDF,然后使用FPDF根据填写的表单填写信息,我在FPDF中设置了一个SetPage方法,以便能够设置我正在处理的页面,我能够完全写好第一个文件(前3页) . 但是,当我试图写第二个文件(第4个和继续页面)时,我使用SetXY和Write但没有写任何内容,我能够添加图像(页面底部的条形码)但没有文字关于我做错了什么的任何想法?

这是我必须连接文件的代码:

<?php
session_start();
require_once('lib/pdf/fpdf.php');
require_once('lib/pdi/fpdi.php');
require_once('lib/barcode/class/BCGFontFile.php');
require_once('lib/barcode/class/BCGColor.php');
require_once('lib/barcode/class/BCGDrawing.php');
require_once('lib/barcode/class/BCGcode39extended.barcode.php');

$contractType = $_SESSION['addition'];

require_once('barcode.php');

 if(isset($contractType))
   {
    $files = array('lib/blank/NDA.pdf');

       if($contractType = 'artist')
       {
           array_push ($files,
               'lib/blank/Distro.pdf',
               'lib/blank/Management-Trial.pdf'
           );
       } else {
           echo "Whoops! Something must've happened when you were filling out your contracts! Please try filling them out again. Sorry!";
       }
   }

$pdf = new FPDI();
   foreach ($files AS $file) {
       $pageCount = $pdf->setSourceFile($file);
       for($n = 1; $n <= $pageCount; $n++) {
           $tmpIdx = $pdf->importPage($n);
           $size = $pdf->getTemplateSize($tmpIdx);
           if($size['w'] > $size['h']) {
               $pdf->AddPage('L', array($size['w'], $size['h']));
           } else {
               $pdf->AddPage('P', array($size['w'], $size['h']));
           }
           $pdf->useTemplate($tmpIdx);
       }
   }
    //NDA FILLER
    include('lib/filler/NDA.php');
    //Distro Contract Filler
    include('lib/filler/Distro.php');

//session_unset();
$pdf->Output();
?>

这是填写第一个PDF(完全正常)的代码:

NDA.php

<?php
//ID No.
$idcoded = 'idbars/'.$_SESSION['name'].'.png';
/*
for($p = 2; $p <= $pages; $p++) 
{
    $pdf->Image($idcoded,0,350);
    $pdf->setPage($p);
}
*/

$pdf->SetPage(1);
$pdf->Image($idcoded,0,350);
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(255, 0, 0);
//NDA DATE
$pdf->SetXY(51, 109.5);
$pdf->Write(0, date(d));
$pdf->SetXY(72, 109.5);
$pdf->Write(0, date(F));
//Legal Name
$pdf->SetXY(72, 114.5);
$pdf->Write(0, $_SESSION['name']);
//stage Name
$pdf->SetXY(80, 119.5);
$pdf->Write(0, $_SESSION['sname']);

$pdf->setPage(2);
$pdf->Image($idcoded,0,350);
$pdf->setPage(3);
$pdf->Image($idcoded,0,350);
$signature = 'idbars/'.$_SESSION['name'].'_sig.png';
$pdf->Image($signature,20,105,100);


?>

这就是我用来尝试在第二个PDF上写的内容,我尝试将NDA.php和Distro.php合并到一个文件中,这没什么区别

Distro.php

<?php

$pdf->SetPage(4);
$pdf->SetXY(10,10);
$pdf->Cell(0, $_SESSION['name']);
$pdf->Write(0, $_SESSION['name']);
$pdf->Image($idcoded,0,350);
?>

这个构建的页面使用以下形式:

https://secure.gr8label.com/sign/artist/Dev%20Test/

1 回答

  • 0

    FPDF“缓存”当前使用的字体信息 . 当你跳回到另一个页面时,FPDF“认为”字体已经定义/设置,但在PDF文件本身却没有 . 您应该在导入循环中设置字体和大小,以确保字体在所有页面上都可用(我认为它也可以起作用,通过仅在第一个页面上定义它) .

    无论如何你应该已经看到在书面页面之间跳跃会导致问题,你应该创建一个逻辑,从上到下创建文件而不使用“SetPage()”之类的东西 .

相关问题