12

I have to merge PDF files when a user needs to. The files are already existing and everything is fine. I'm using the fallowing code to merge the files:

class concat_pdf extends FPDI 
{
    var $files = array();

    function setFiles($files) 
    {
        $this->files = $files;
    }

    function concat() 
    {
        foreach($this->files AS $file) 
        {
            $pagecount = $this->setSourceFile($file);

            for($i = 1; $i <= $pagecount; $i++) 
            {
                $this->AddPage('P');
                $tplidx = $this->ImportPage($i);
                $this->useTemplate($tplidx);
            }
        }
    }
}

$pdf = new concat_pdf();
$pdf->setFiles($files); //$files is an array with existing PDF files.
$pdf->concat();
$pdf->Output("bulk.pdf", "D");

All files are merged and all the content is there. The problem is, at the top of each page in the new file, a black line appears. The contents, margins, etc. are all absolutely the same as the original file, but this line comes out of nowhere (that I can tell). It is not thick, but is clearly visible. It doesn't mess with the other content or anything, but is not needed there and I need to remove it.

I've tried changing the second parameter to the ImportPage() function to all the options described in the documentation, but there's no difference whatsoever. Since this is the only thing that I see I can change in this few lines of code, I really don't know what is causing the black line to appear. I've searched for similar issues, but so far - no luck. Anyone have an idea? Thanks in advance!

before after

Silvan
  • 153
  • 2
  • 12
Nikoloff
  • 3,426
  • 1
  • 15
  • 18
  • Would you add a screenshot? - would probably be the best way of illustrating the issue. – halfer May 09 '12 at 20:30
  • I added screenshots, but since I cannot reveal the contents of the files, I've only cut what is seen at the top when opening the same file - once normal, once merged with other files. Everything below is absolutely identically positioned. – Nikoloff May 09 '12 at 20:40

3 Answers3

23

A better thing to do as you won't have to modify the source is to add the lines:

    $this->setPrintHeader(false);
    $this->setPrintFooter(false);

at the beginning of your concat() function.

Robert
  • 231
  • 1
  • 2
4

To avoid editing the TCPDF library, overwrite the methods Footer and Header in your extended class.

class concat_pdf extends FPDI 
{
    public function Footer() {}
    public function Header() {}
}
1

I have solution of this issue. Default header and footer in tcpdf contains line. You have to erase body of methods footer() and header() in tcpdf class on line 4214.

tristenn
  • 11
  • 1