TCPDF watermark images work only on first few pages of output PDF

青春壹個敷衍的年華 提交于 2020-01-24 00:32:08

问题


I am extending the TCPDF library to add a Header function which includes a watermark image.

class PdfWrapperDraft extends PdfWrapper {
    // TODO: Rename to PdfWrapperWatermark and allow any watermark, not just the DRAFT image.
    public function Header()
    {
        // get the current page break margin
        $bMargin = $this->getBreakMargin();
        // get current auto-page-break mode
        $auto_page_break = $this->AutoPageBreak;
        // disable auto-page-break
        $this->SetAutoPageBreak(false, 0);

        // set background image: in actual practice, all but one of the lines below would be commented out.
        $img_file = K_PATH_IMAGES . 'image_demo.jpg'; // This inbuilt sample image works fine.
        $img_file = BD . PP . '/images/image_demo.png'; // The sample image also works when copied to another directory.
        $img_file = BD . PP . '/images/image_demo.png'; // The sample image still works when converted to PNG.
        $img_file = BD . PP . '/images/DRAFT.jpg'; // This watermark image also works fine.
        $img_file = BD . PP . '/images/DRAFT.png'; // This is the one I actually want, and it appears only on the first four pages. Why?!

        $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 0, '', false, false, 0);
        // restore auto-page-break status
        $this->SetAutoPageBreak($auto_page_break, $bMargin);
        // set the starting point for the page content
        $this->setPageMark();
    }
}

As the comments in the code make clear, the sample TCPDF JPEG image works fine as a watermark, appearing on all 52 pages of the PDF document. It continues to work when loaded from a different folder, and when converted to PNG.

My own supplied image also works on all 52 pages of the PDF as a JPEG, but is too heavy to function as a watermark: the text over it is hard to read. However, when I try the PNG that I actually want to use, it works beautifully on the first four pages, and then disappears. What on Earth is going on?

Experimenting with different sizes of image, and different page sizes (A4, A5), sometimes the image will last a few pages more or less, but it always disappears after the first few pages.

image_demo.png:

Width: 1181 pixels
Height: 1772 pixels
Bytes: 3.8 MB

DRAFT.png:

Width: 1181 pixels
Height: 1772 pixels
Bytes: 105.1 kB

来源:https://stackoverflow.com/questions/59720761/tcpdf-watermark-images-work-only-on-first-few-pages-of-output-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!