Nikoloff
Nikoloff

Reputation: 4160

FPDI merge PDF files, strange line appears

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

Upvotes: 14

Views: 10232

Answers (3)

Javier Tac&#243;n
Javier Tac&#243;n

Reputation: 71

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() {}
}

Upvotes: 5

Robert
Robert

Reputation: 281

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.

Upvotes: 28

tristenn
tristenn

Reputation: 9

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.

Upvotes: 0

Related Questions