dongma0722 2011-04-26 05:18
浏览 66
已采纳

使用FPDI和FDP生成略有不同的pdf文件

i first import a pdf using fpdi to make a fpdf object, i then perform several changes on that pdf. I clone it to make a custom pdf just adding some texts. Then i output the two files to disk but just one is created and i got a fatal error for the second output :

Fatal error: Call to undefined method stdClass::closeFile() in C:\Program Files\EasyPHP 3.0\www\oursin\oursin\public\scripts\FPDI\fpdi.php on line 534

pieces of my code:

$pdf = new FPDI('L','mm',array(291.6,456)); 
$fichier=$repertoireGrilles.'GR_IFR.pdf';   

$pdf->setSourceFile($fichier); 
// add a page 
$tplIdx = $pdf->importPage(1); 
$pdf->AddPage(); 
$pdf->useTemplate($tplIdx,0,0,0); 
.. 
... 
methods on $pdf 
.. 
.. 
.. 

$pdfCopie=clone $pdf; 

methods on $pdfCopie

$pdfCopie-> Output($repertoireGrilles.'grillesQuotidiennes/'.$date.'/Grille_'.$date.'_'.$ou.'_copie.pdf','F'); 
$pdf-> Output($repertoireGrilles.'grillesQuotidiennes/'.$date.'/Grille_'.$date.'_'.$ou.'.pdf','F'); 

Anybody to help me to tackle this issue that keeps my brain under high pressure for hours (days) :) ?

  • 写回答

1条回答 默认 最新

  • dsuikgi9199 2015-05-14 15:39
    关注

    Cloning, forking, copying, any of that is really dirty. You will have a very hard time with outputs if you take that route. Instead, consider this approach:

    1. Make multiple AJAX calls to a single PHP file, pass a pid value to it so as to differentiate between them.
    2. Go through the exact same document setup for FPDI. This is far more consistent than cloning, forking, copying, etc.
    3. Check pid and do different things to different documents after all the setup is done.
    4. Output the documents.

    Here is my jQuery:

    $(document).ready(function(){
        var i;
        for( i=0; i<=1; i++ )
        {
            $.ajax({
                url:    'pdfpid.php',
                data:   {
                    pid:    i,
                    pdf:    'document.pdf'
                },
                type:   'post'
            });
        }
    });
    

    As you can see, it's pretty simple. pdfpid.php is the name of the file that will generate and process the documents. In this case, I want the document with a pid of 0 to be my "original" and the one with a pid of 1 to be the "cloned" document.

    //  Ensure that POST came in correctly
    if( !array_key_exists('pid',$_POST) || !array_key_exists('pdf',$_POST) )
        exit();
    
    //  Populate necessary variables from $_POST
    $pid    = intval($_POST['pid']);
    $src    = $_POST['pdf'];
    
    //  Setup the PDF document
    $pdf = new FPDI();
    $pdf->setSourceFile($src);
    $templateID = $pdf->importPage(1);
    $pdf->addPage();
    $pdf->useTemplate($templateID);
    $pdf->SetFont('Arial','B',24);
    
    switch( $pid )
    {
        default:
            break;
        case 0:
            //  "Parent" document
            $pdf->Text(10,10,"ORIGINAL");
            $filename = "original.pdf";
            break;
        case 1:
            //  "Child" document
            $pdf->Text(10,10,"CLONED");
            $filename = "cloned.pdf";
            break;
    }
    
    $pdf->Output($filename,'F');
    

    I got both documents as an output, with the unique modifications between the "parent" and the "child" all in place.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)