WordPress.org

Ready to get started?Download WordPress

Forums

WP Post to PDF
[resolved] background-image (5 posts)

  1. Twanneman
    Member
    Posted 1 year ago #

    I've found this code to include a background-image :

    class MYPDF extends TCPDF {
    	public function Header() {
    		$bMargin = $this->getBreakMargin();
    		$auto_page_break = $this->AutoPageBreak;
    		$this->SetAutoPageBreak(false, 0);
    		$img_file = K_PATH_IMAGES.'background.jpg';
    		$this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
    		$this->SetAutoPageBreak($auto_page_break, $bMargin);
    		$this->setPageMark();
    	}
    }
    
    $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

    I've paste these lines into the wp-post-to-pdf.php file > function generate_pdf_file after the lines :

    if(!class_exists('TCPDF'))				{ require_once(WPPT0PDF_PATH . '/tcpdf/tcpdf.php'); }
                if(!class_exists('simple_html_dom'))	{ require_once(WPPT0PDF_PATH . '/simplehtmldom/simple-html-dom.php');}

    But then the script stops working.
    I know alot of people want a background image for the generated PDF, could you please post an example ?

    Kind regards, Twan

    http://wordpress.org/extend/plugins/wp-post-to-pdf/

  2. Twanneman
    Member
    Posted 1 year ago #

    never mind, already figured it out :

    I've added the following line

    if(!class_exists('MYPDF'))				{ require_once(WPPT0PDF_PATH . '/tcpdf/background.php'); }

    after :

    if(!class_exists('TCPDF'))				{ require_once(WPPT0PDF_PATH . '/tcpdf/tcpdf.php'); }

    and placed these lines in a new file background.php located in the tcpdf folder :

    <?php
    // Extend the TCPDF class to create custom Header and Footer
    class MYPDF extends TCPDF {
        //Page header
        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 bacground image
    		$img_file = WPPT0PDF_PATH .'/tcpdf/images/background.jpg';
            $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
            // restore auto-page-break status
            $this->SetAutoPageBreak($auto_page_break, $bMargin);
            // set the starting point for the page content
            $this->setPageMark();
        }
    }
    ?>

    The image file is 1181px by 1772px and located in the tcpfg/images folder

  3. stheoret
    Member
    Posted 8 months ago #

    Could you provide me the complete file wp-post-to-pdf.php ???

    I am following your steps but my website get me a 500 error ...

    I saw some parenthesis who are not in my original file and that you show in your explanations... might miss something...

    So with this complete file, i think i'll not have any other errors...

    Thank's for your help as i need this asap.

    Stephane

  4. stheoret
    Member
    Posted 8 months ago #

    Forget about my demand !

    I have now the BACKGROUND IMAGE in the PDF !!!

    I needed to use the updated package 2.3.6.

    Everything is perfect now!

    Thank you man for that precious coding!!!

    Stephane

  5. Twanneman
    Member
    Posted 8 months ago #

    No problem! I'm glad you solved it!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic