English 中文(简体)
用fpdf生成的pdf文档显示变数
原标题:To show php variable in pdf file generated using fpdf

我想在pdf文档中显示这一变数。 但它造成错误: Pdf 档案不以%开始

A.php it contains my form . By using post i am sending values to other 印本 Where 印本 generates a pdf file with a specific format .

A.php

 <form class="mid" action="印本" method="post"> 
 <input type="hidden" id="cname" name="cname" value="<?php echo $c_n[0]; ?>"/>
  <input type="submit" id="but" value="Print Challan"/>     
 </form>

印本

 <?php

  $c_n = $_POST[ cname ];


  require( fpdf.php );
 class PDF extends FPDF
     {

     function Header()
    {
       $this->Image( image.jpg ,5,5,200);
       $this->Ln(20);
       }

     //Page footer
     function Footer()
   {
       $this->SetFont( Arial , I ,8);
       $this->Image( image1.jpeg ,5,275,200);
       $this->SetXY(5, 284);
       $this->Cell(0,5, This is a system generated  ,0,2, C );
       $this->Cell(0,5, Page  .$this->PageNo(). /{nb} ,0,0, C );

       }
        }
         //Instanciation of inherited class

       $pdf=new PDF();
       $pdf->AliasNbPages();
       $pdf->AddPage();
       $pdf->SetFont( Times , B ,15);
       $pdf->SetXY(5,42);
       $pdf->Cell(190,10, Challan , 0,0, C );
       $pdf->SetXY(5,52);
       $pdf->SetFont( Times , B ,12);
       $pdf->Cell(150,18, Name :- , 1,0, L );


       $pdf->Cell(15,0, $c_n , 0,0, L );

       $pdf->SetXY(155,52);
       $pdf->Cell(50,9, Challan No. :- , 1,2, L );
       $pdf->Cell(50,9, Date :- , 1,0, L );
       $pdf->SetXY(5,70);
       $pdf->Cell(15,15, Sno , 1,0, C );
       $pdf->Cell(35,15, Type , 1,0, C );
       $pdf->Cell(45,15, Make , 1,0, C );
       $pdf->Cell(45,15, Model , 1,0, C );
       $pdf->Cell(45,15, Serial No. , 1,0, C );
       $pdf->Cell(15,15, Qty , 1,0, C );
       $pdf->SetXY(5,85);
       $pdf->SetFont( Times ,  ,12);
       $pdf->Cell(15,165,  , 1,0, L );
       $pdf->Cell(35,165,  , 1,0, L );
       $pdf->Cell(45,165,  , 1,0, L );
       $pdf->Cell(45,165,  , 1,0, L );
       $pdf->Cell(45,165,, 1,0, L );
       $pdf->Cell(170,165,  , 1,0, L );
       $pdf->Cell(15,165,  , 1,0, L );
        $pdf->SetXY(5,245);
       $pdf->SetFont( Times , B ,12);
       $pdf->Cell(35,20, Reciever Name :-  , 0,0, L );
       $pdf->SetXY(125,245);
        $pdf->Cell(35,20, Reciever Signature :-  , 0,0, L );
       $pdf->Output();
          ?>

原文: 档案从%开始

问题回答

I recommend avoid hidden input fields to parse variables. Better use the url itself when calling to action: action="printpdf.php?cname=XXXX". If the variable can be spoiled by the user, do one of three things: i)store the variable in server session: $_SESSION[ cname ]=XXXX; where it can t hardly be manipulated; ii)encode, hash or encrypt the url string; iii) sanitize the variable when recovering in the printpdf.php file. Hidden fields are easy to manipulate and are a primitive way of parsing data.

采用这种方式:

<?php
 require( fpdf.php );
 class PDF extends FPDF
 {

 function Header()
  {
   $this->Image( image.jpg ,5,5,200);
   $this->Ln(20);
   }

 //Page footer
 function Footer()
 {
   $this->SetFont( Arial , I ,8);
   $this->Image( image1.jpeg ,5,275,200);
   $this->SetXY(5, 284);
   $this->Cell(0,5, This is a system generated  ,0,2, C );
   $this->Cell(0,5, Page  .$this->PageNo(). /{nb} ,0,0, C );

   }
    }
     //Instanciation of inherited class

   if(isset($_POST[ cname ]))
   {$c_n = $_POST[ cname ];

   $pdf=new PDF();
   $pdf->AliasNbPages();
   $pdf->AddPage();
   $pdf->SetFont( Times , B ,15);
   $pdf->SetXY(5,42);
   $pdf->Cell(190,10, Challan , 0,0, C );
   $pdf->SetXY(5,52);
   $pdf->SetFont( Times , B ,12);
   $pdf->Cell(150,18, Name :- .$c_n, 1,0, L );


   $pdf->Cell(15,0,$c_n, 0,0, L );

   $pdf->SetXY(155,52);
   $pdf->Cell(50,9, Challan No. :- , 1,2, L );
   $pdf->Cell(50,9, Date :- , 1,0, L );
   $pdf->SetXY(5,70);
   $pdf->Cell(15,15, Sno , 1,0, C );
   $pdf->Cell(35,15, Type , 1,0, C );
   $pdf->Cell(45,15, Make , 1,0, C );
   $pdf->Cell(45,15, Model , 1,0, C );
   $pdf->Cell(45,15, Serial No. , 1,0, C );
   $pdf->Cell(15,15, Qty , 1,0, C );
   $pdf->SetXY(5,85);
   $pdf->SetFont( Times ,  ,12);
   $pdf->Cell(15,165,  , 1,0, L );
   $pdf->Cell(35,165,  , 1,0, L );
   $pdf->Cell(45,165,  , 1,0, L );
   $pdf->Cell(45,165,  , 1,0, L );
   $pdf->Cell(45,165,, 1,0, L );
   $pdf->Cell(170,165,  , 1,0, L );
   $pdf->Cell(15,165,  , 1,0, L );
    $pdf->SetXY(5,245);
   $pdf->SetFont( Times , B ,12);
   $pdf->Cell(35,20, Reciever Name :-  , 0,0, L );
   $pdf->SetXY(125,245);
    $pdf->Cell(35,20, Reciever Signature :-  , 0,0, L );
   $pdf->Output();
   }
      ?>

我也坐在同一个时候,我想要提出带有一系列问题和选择的问答文件。

不管怎样,它必须先到require(fpdf.php);

国防军的特意是,在军法之间要制定任何其他法典。

我希望,这个问题得到解决。

过错

      $pdf->Cell(35,165,  , 1,0, L );
   $pdf->Cell(45,165,  , 1,0, L );
   $pdf->Cell(45,165,  , 1,0, L );//*
   $pdf->Cell(45,165,, 1,0, L ); <<<<<<<<<<-----------------
   $pdf->Cell(170,165,  , 1,0, L );
   $pdf->Cell(15,165,  , 1,0, L );
    $pdf->SetXY(5,245);
   $pdf->SetFont( Times , B ,12);
   $pdf->Cell(35,20, Reciever Name :-  , 0,0, L );
   $pdf->SetXY(125,245);
    $pdf->Cell(35,20, Reciever Signature :-  , 0,0, L );
    //*/
   $pdf->Output();

改为$pdf->Cell(45,165, 1,0 L );

注意你的提法,即使用

 $str =  ../fpdf/fpdf.php ;

(千美元)

because there is where my code is an in images i.e. $this->Image($_SESSION[ raiz ]. imagens/mmp.png ,5,5,200); if you have your fpdf library and images in the same folder then all is right. by the way. i test the code correct error and it runs well





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签