I can't seem to find any FPDF forums, or internet posts addressing my problem. I am hoping one of the php gurus can help.

I'm scratching the surface of FPDF and encountered a perplexing problem. If I set the PDF's page up for an 8-1/2 by 11 sheet:

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

and I draw, for example, a rectangle that is 8 wide by 10.5 inches tall I end up with a PDF that prints a rectangle that .25 from the left margin and 7-1/4 inches wide by 9-1/2 tall.

Any ideas?

$pdf = new FPDF('P', 'in', 'letter');  
$pdf->AddPage(); $pdf->SetFont('Arial','',10); $pdf->Rect(.25,.25,8,10.5); // Draw encompassing rectangle $pdf->Output();
    Weedpacket;11042641 wrote:

    Huh. I just tried your code and it worked fine.
    If it helps, there is a forum on the FPDF site.

    I've got the solution...and its an unhappy one. It didn't occur to me to try the PDF printing routine while in another browser. Apparently Firefox shrinks the page down...Chrome and Internet Explorer print the page fine. I must have spent 10 hours on this stupid problem. Any thoughts why Firefox should be choking on this routine?

    Thanks for the link to the forum.

    robkir

      My thinking is that you don't want browsers displaying the PDFs internally and that you should force a download of the PDF file to be opened with the appropriate desktop application.

        sneakyimp;11042685 wrote:

        My thinking is that you don't want browsers displaying the PDFs internally and that you should force a download of the PDF file to be opened with the appropriate desktop application.

        Seems like the way to go. I did a bit of searching but couldn't find anything that worked. Can you point me to an example showing how to force a download of the PDF?

          sneakyimp;11042699 wrote:

          googling "php force pdf download" yields this result:

          http://webdesign.about.com/od/php/ht/force_download.htm

          I haven't read it thoroughly or tried it, but a cursory read says it looks pretty good.

          I got it to work. But here's a point of confusion: The PDFs that I am creating are dynamically created with different data for different users. Since this routine creates a PDF (document.pdf) residing on the server, would there be a problem if User #1 creates his PDF and a second later, User #2 creates a different one (with different data). Could User #1 end up with User #2's PDF? Also, is it okay to have the dynamically created PDF placed in the same directory as the PDF creating PHP?

          Here's the test code, in case anybody else might need it.

          require('fpdf.php');
          
          header("Content-disposition: attachment; filename=document.pdf");
          header("Content-type: application/pdf");
          $pdf = new FPDF('P', 'in', 'letter');  
          $pdf->AddPage(); $pdf->SetFont('Arial','',10); $pdf->Rect(.25,.25,8,10.5); // Draw encompassing rectangle Left $pdf->Cell(4,.30,"Banana",0,1,'L'); $pdf->output('document.pdf', 'F');

            Oops. I left out a piece of necessary code in the PDF example. It needs the readfile to work properly

            require('fpdf.php');
            
            header("Content-disposition: attachment; filename=document.pdf");
            header("Content-type: application/pdf");
            readfile("document.pdf");
            $pdf = new FPDF('P', 'in', 'letter');  
            $pdf->AddPage(); $pdf->SetFont('Arial','',10); $pdf->Rect(.25,.25,8,10.5); // Draw encompassing rectangle Left $pdf->Cell(4,.30,"Peanut Butter",0,1,'L'); $pdf->output('document.pdf', 'F');

              I'm not sure you need the file at all; you can just output the result directly to the browser as you were before (which doesn't care where the server got it from). The headers tell the browser how to treat it.

              (But to answer your questions: the answer to both is yes, but neither is generally a good thing)

                Okay...this version appears to fly. Apparently it doesn't need the

                header("Content-disposition: attachment; filename=document.pdf");
                header("Content-type: application/pdf");
                readfile("document.pdf");
                

                The revised code is:

                require('fpdf.php');
                
                $pdf = new FPDF('P', 'in', 'letter');  
                $pdf->AddPage(); $pdf->SetFont('Arial','',10); $pdf->Rect(.25,.25,8,10.5); // Draw encompassing rectangle Left $pdf->Cell(4,.30,"Client Data Here",0,1,'L'); $pdf->output('gameCardPrintOut.pdf', 'D');

                I tested it in IE, Firefox, and Chrome.

                Thanks for input.

                  robkir;11042701 wrote:

                  The PDFs that I am creating are dynamically created with different data for different users. Since this routine creates a PDF (document.pdf) residing on the server, would there be a problem if User #1 creates his PDF and a second later, User #2 creates a different one (with different data). Could User #1 end up with User #2's PDF?

                  This could in fact happen and proper code would take care to a) make sure different users' files are saved with unique names (consider using [man]uniqid[/man] to generate different ones) and b) make sure that the script deletes the file when it is finished with it so that your server's hard drive doesn't end up full of PDFs.

                  robkir;11042701 wrote:

                  Also, is it okay to have the dynamically created PDF placed in the same directory as the PDF creating PHP?

                  I'm not sure exactly what you mean here.

                    sneakyimp;11042729 wrote:

                    This could in fact happen and proper code would take care to a) make sure different users' files are saved with unique names (consider using [man]uniqid[/man] to generate different ones) and b) make sure that the script deletes the file when it is finished with it so that your server's hard drive doesn't end up full of PDFs.

                    If I was storing the PDF file on the server, uniqid would make sense, but I am bypassing that step and downloading directly to the user. I haven't actually had any users try it -- but I tested it on three systems at the office and it worked fine.

                      Write a Reply...