SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    May 2008
    Location
    Missouri, USA
    Posts
    273
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    FPDF/FPDI Margin Problem

    I'm using FPDF/FPDI to import a pdf and add a header to the page. Everything is working perfectly except a margin is being placed at the bottom of the page that I can't seem to get rid of. I think what happens is that fpdi imports the pdf page (which already has a footer margin at the bottom) and then fpdf adds an additional margin below the imported pdf page. The problem is that instead of having 11'' tall pdfs they are 11.69'' tall (to tall for printing). Can anyone think of any tricks to remove this margin? I've looked through the fpdf documentation and have tried a couple things but nothing seems to be working.

    My Code:
    PHP Code:
    <?php
    require_once('fpdf.php');
    require_once(
    'fpdi.php');


    $journal "Title";
    $volume "1";
    $cid "111111";
    $year "2009";
    $doi "10.1234";
    $issn "1234-5678";

    $line1 $journal ", " $volume ", " $cid " (" $year ")";
    $line2 "DOI: " $doi;
    $line3 "Name";
    $line4 "ISSN: " $issn;

    $galleyFile "test.pdf";

    $pdf =& new FPDI();

    $pagecount $pdf->setSourceFile($galleyFile);

    //I was trying to use this to reduce the margin but it doesn't seem to be doing
    //anything
    $pdf->SetAutoPageBreak(true0);

    $pdf->addPage();

    for (
    $n 1$n <= $pagecount$n++) {

    //Add the header
    $pdf->SetFont('Arial'''8);
    $pdf->SetXY(1010); 
    $pdf->MultiCell(0''$line1 false);
    $pdf->SetXY(1014); 
    $pdf->MultiCell(0''$line2 false);
    $pdf->SetXY(16010); 
    $pdf->MultiCell(0''$line3 false);
    $pdf->SetXY(16014); 
    $pdf->MultiCell(0''$line4 false);

    //Import 1 page and set as a template
    $tplidx $pdf->ImportPage($n);
    $size $pdf->useTemplate($tplidx);
        
    //Repeat for all pages in the pdf.
        
    if ($n != $pagecount) {
            
    $pdf->AddPage();      
        }
    }


    $pdf->Output($galleyFile'F');
    ?>
    Follow Me On Twitter: BryceRay

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2009
    Location
    Bavaria, Germany
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried creating a new class which extends the FPDF class and overwrite the Footer method?

    PHP Code:
    require_once('fpdf.php');
    require_once(
    'myfpdf.php');
    require_once(
    'fpdi.php'); 
    myfpdf.php
    PHP Code:
    class MyFPDF extends FPDF{
      function 
    Footer() {
        
    $this->SetY(0);
      }


  3. #3
    SitePoint Member
    Join Date
    Mar 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It appears that FPDF defaults to A4 paper size if you initialize it like this:

    PHP Code:
    $pdf = new FPDF(); 
    Instead initialize FPDF like this:

    PHP Code:
    $pdf = new FPDF('P','mm','Letter'); 
    The above example is for P - portrait, mm - millimeter, Letter - paper size.

  4. #4
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For posterity, i just wanted to say that changing the default FPDF() params fixed everything. I've been struggling with this for days.

    Thanks Robert!

  5. #5
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just another point: new pages are automatically created if body text reaches the trigger distance set in SetAutoPageBreak with a default of 2cm. Set SetAutoPageBreak(true, 0) to use the full page before a new one is created.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •