FPDI merge PDF files, strange line appears
Asked Answered
S

3

14

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

Scalenus answered 9/5, 2012 at 20:16 Comment(2)
Would you add a screenshot? - would probably be the best way of illustrating the issue.Sanyu
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.Scalenus
V
27

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.

Verity answered 4/6, 2012 at 20:43 Comment(1)
Thank you, simple but effective. :)Cr
Q
5

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() {}
}
Quadrillion answered 7/5, 2013 at 7:32 Comment(0)
H
0

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.

Himyaritic answered 17/5, 2012 at 11:23 Comment(1)
You should not edit the tcpdf class itself as it can be easily overwritten if you update the lib.Iveyivie

© 2022 - 2024 — McMap. All rights reserved.