Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:51:57+00:00 2026-05-26T09:51:57+00:00

I’ve written some code which created reports and then exports it to .PDF using

  • 0

I’ve written some code which created reports and then exports it to .PDF using TCPDF.
I want to send different parts of the report to mail , therefor I need to use the function WriteHTML() more than once in order to create multiple pdf files and save them in a specific directory.

    $parts=explode("<div class='subTable'>",$html);
    pdf->writeHTML($html, true, false, false, false, '');
    $pdf->Output('exmpl/example_045.pdf', 'I');
    $pdf->Output('exmpl/example_046.pdf', 'F');
    $pdf->writeHTML($parts[2], true, 0, true, 0);
    //Close and output PDF document
    $pdf->Output('exmpl/example_048.pdf', 'F');

Altough I try to export two different files to the directory exmpl , all I actually get is one file (example_046.pdf).

I have to mention that I can use Output() more than once and I’ve already done such thing, but I just can’t use writeHTML() more than once.

Any solution will be appreciated,
Thanks in advance !

EDIT

Here’s the full code :

<?php
function createPDF($html, $type, $filename, $output,$saleStart,$saleEnd,$reportType)
    {

    //REQUIRE TCPDF
    require_once('tcpdf/config/lang/eng.php');
    require_once('tcpdf/config/lang/heb.php');
    require_once('tcpdf/tcpdf.php');

class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Set font
        $this->SetFont('helvetica', 'B', 20);
        // Title
        $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    }

    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);
        // Page number
        $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }
}



// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
/*
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 018');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
*/
// SET CUSTOMIZED DATE INCLUDED HEADER
$headerSDate=reverseLongDate($saleStart);
$headerEDate=reverseLongDate($saleEnd);
$header="";
$header.="\t";
$header.=Date("d-m-Y h:m:s");
$header.="\n";
$header.='מועדון המגדלים יוסי חותה פירות וירקות';
$header.="\n";
if($reportType=='customer')
{
    $header.='דו"ח שיווק ללקוח לתאריכים '.$headerSDate." עד ".$headerEDate;
}
else
    if($reportType=='newCustomer')
    {
        $header.='דו"ח שיווק ללקוח לתאריכים '.$headerSDate." עד ".$headerEDate;
    }
    else 
        if($reportType=='collection')
            {
            $header.='דו"ח גביה ללקוח לתאריכים '.$headerSDate." עד ".$headerEDate;
            }
                else 
                    if($reportType=='grower')
                    {
                        $header.='דו"ח מגדל ללקוח לתאריכים '.$headerSDate." עד ".$headerEDate;
                    }



$pdf->SetHeaderData("","" ,"",$header); 
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);



// set header and footer fonts
$pdf->setHeaderFont(Array("dejavusans", '', "15"));
$pdf->setFooterFont(Array("dejavusans", '', "12"));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language dependent data:
$lg = Array();
$lg['a_meta_charset'] = 'UTF-8';
$lg['a_meta_dir'] = 'rtl';
$lg['a_meta_language'] = 'fa';
$lg['w_page'] = 'page';

//set some language-dependent strings
$pdf->setLanguageArray($lg);

// ---------------------------------------------------------

// set font
$pdf->SetFont('dejavusans', '', 12);

// add a page
$pdf->AddPage();
// -----------------------------------------------------------------------------

        if($type == "all"){
            $pdf->writeHTML($html, true, false, false, false, '');
        } elseif($type == "partial"){
            $parts = explode("<div class='subTable'>", $html);
            $pdf->writeHTML($parts[2], true, 0, true, 0);
        }
        ob_clean();
        $pdf->Output('exmpl/' . $filename . '.pdf', $output);
    } //END_OF_FUNCTION

set_time_limit(0);
require('modifyDate.php');
require('createQuery.php');

//GET FORM DATA
if(isset($_POST['submitMeshavek']))
{
$saleStart=$_POST['saleStart'];
$saleEnd=$_POST['saleEnd'];
$saleWeek=$_POST['weekId'];
$growerId=$_POST['growerId'];
$reportType=$_POST['reportType'];
}





/*
$regularSaleStart=reverseDate($saleStart);
$regularSaleEnd=reverseDate($saleEnd);
$header='<h2>מועדון מגדלים יוסי חותה פירות וירקות</h2>';
$header.="דוח שיווק ללקוח לתאריכים                 ".$regularSaleEnd." ".$regularSaleStart;

 public function Header() {
        // Set font
        $this->SetFont('dejavusans', '', 10);
        // Title
        $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    }
*/

if($reportType=='customer')
{
    include('reportType/customer.php');
}
else
    if($reportType=='newCustomer')
    {
        include('reportType/customerNew.php');
    }
    else 
        if($reportType=='collection')
            {
            include('reportType/collect.php');
            }
                else 
                    if($reportType=='grower')
                    {
                        include('reportType/grower.php');
                    }


createPDF($html, "all", "example_045", "I",$saleStart,$saleEnd,$reportType);                    
createPDF($html, "partial", "example_048", "F",$saleStart,$saleEnd,$reportType);
createPDF($html, "all", "example_046", "F",$saleStart,$saleEnd,$reportType);



/*
ob_clean();
//$pdf->writeHTML($html, true, false, false, false, '');
$pdf->writeHTML($html, true, 0, true, 0);
//Close and output PDF document
$pdf->Output('example_048.pdf', 'I');

$pdf->writeHTML($html, true, 0, true, 0);
//Close and output PDF document
$pdf->Output('examp.pdf', 'I');
*/

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:51:57+00:00Added an answer on May 26, 2026 at 9:51 am

    Your problem is that after the $pdf->Output('exmpl/example_045.pdf', 'I'), and as if the script ends there. Why shoot to the file header.

    You can not shoot at two different header files, if you want to generate two distinct pdf I recommend you go with the function outputs the string

    $pdf->Output('', 'S');
    

    thus these two files on the filesystem save them and shoot.
    Compress the files and shoot the zipped file header containing the two pdf.

    UPDATE

    in your case I would use a similar approach:

    function createPDF($html, $type, $filename, $output)
        {
            $pdf = new TCPDF();
            //... code ...
            if($type == "all"){
                $pdf->writeHTML($html, true, false, false, false, '');
            } elseif($type == "partial"){
                $parts = explode("<div class='subTable'>", $html);
                $pdf->writeHTML($parts[2], true, 0, true, 0);
            }
            $pdf->Output('exmpl/' . $filename . '.pdf', $output);
        }
    
    createPDF($html, "partial", "example_048", "F");
    createPDF($html, "all", "example_046", "F");
    createPDF($html, "all", "example_045", "I");
    

    Final Update

    right code:

    <?php
    
    //REQUIRE TCPDF
    require_once('tcpdf/config/lang/eng.php');
    require_once('tcpdf/config/lang/heb.php');
    require_once('tcpdf/tcpdf.php');
    
    class MYPDF extends TCPDF
    {
    
        //Page header
        public function Header()
        {
            // Set font
            $this->SetFont('helvetica', 'B', 20);
            // Title
            $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
        }
    
        // Page footer
        public function Footer()
        {
            // Position at 15 mm from bottom
            $this->SetY(-15);
            // Set font
            $this->SetFont('helvetica', 'I', 8);
            // Page number
            $this->Cell(0, 10, 'Page ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
        }
    
        // Create PDF
        function createPDF($html, $type, $filename, $output, $saleStart, $saleEnd, $reportType)
        {
            // create new PDF document
            $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    
            // set document information
            /*
            $pdf->SetCreator(PDF_CREATOR);
            $pdf->SetAuthor('Nicola Asuni');
            $pdf->SetTitle('TCPDF Example 018');
            $pdf->SetSubject('TCPDF Tutorial');
            $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
            */
            // SET CUSTOMIZED DATE INCLUDED HEADER
            $headerSDate = reverseLongDate($saleStart);
            $headerEDate = reverseLongDate($saleEnd);
            $header = "";
            $header .= "\t";
            $header .= Date("d-m-Y h:m:s");
            $header .= "\n";
            $header .= 'מועדון המגדלים יוסי חותה פירות וירקות';
            $header .= "\n";
            if ($reportType == 'customer') {
                $header .= 'דו"ח שיווק ללקוח לתאריכים ' . $headerSDate . " עד " . $headerEDate;
            }
            elseif ($reportType == 'newCustomer') {
                $header .= 'דו"ח שיווק ללקוח לתאריכים ' . $headerSDate . " עד " . $headerEDate;
            }
            elseif ($reportType == 'collection') {
                $header .= 'דו"ח גביה ללקוח לתאריכים ' . $headerSDate . " עד " . $headerEDate;
            }
            elseif ($reportType == 'grower') {
                $header .= 'דו"ח מגדל ללקוח לתאריכים ' . $headerSDate . " עד " . $headerEDate;
            }
    
            $pdf->SetHeaderData("", "", "", $header);
            //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
    
    
            // set header and footer fonts
            $pdf->setHeaderFont(Array("dejavusans", '', "15"));
            $pdf->setFooterFont(Array("dejavusans", '', "12"));
    
            // set default monospaced font
            $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    
            //set margins
            $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
            $pdf->SetHeaderMargin(0);
            $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    
            //set auto page breaks
            $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    
            //set image scale factor
            $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    
            // set some language dependent data:
            $lg = Array();
            $lg['a_meta_charset'] = 'UTF-8';
            $lg['a_meta_dir'] = 'rtl';
            $lg['a_meta_language'] = 'fa';
            $lg['w_page'] = 'page';
    
            //set some language-dependent strings
            $pdf->setLanguageArray($lg);
    
            // ---------------------------------------------------------
    
            // set font
            $pdf->SetFont('dejavusans', '', 12);
    
            // add a page
            $pdf->AddPage();
            // -----------------------------------------------------------------------------
    
            if ($type == "all") {
                $pdf->writeHTML($html, true, false, false, false, '');
            } elseif ($type == "partial") {
                $parts = explode("<div class='subTable'>", $html);
                $pdf->writeHTML($parts[2], true, 0, true, 0);
            }
            ob_clean();
            $pdf->Output('exmpl/' . $filename . '.pdf', $output);
        } //END_OF_FUNCTION
    
    }
    
    set_time_limit(0);
    require('modifyDate.php');
    require('createQuery.php');
    
    //GET FORM DATA
    if (isset($_POST['submitMeshavek'])) {
        $saleStart = $_POST['saleStart'];
        $saleEnd = $_POST['saleEnd'];
        $saleWeek = $_POST['weekId'];
        $growerId = $_POST['growerId'];
        $reportType = $_POST['reportType'];
    }
    
    
    if ($reportType == 'customer') {
        include('reportType/customer.php');
    }
    elseif ($reportType == 'newCustomer') {
        include('reportType/customerNew.php');
    }
    elseif ($reportType == 'collection') {
        include('reportType/collect.php');
    }
    elseif ($reportType == 'grower') {
        include('reportType/grower.php');
    }
    
    $myPdf = new MYPDF();
    $myPdf->createPDF($html, "partial", "example_048", "F", $saleStart, $saleEnd, $reportType);
    $myPdf->createPDF($html, "all", "example_046", "F", $saleStart, $saleEnd, $reportType);
    $myPdf->createPDF($html, "all", "example_045", "I", $saleStart, $saleEnd, $reportType);
    
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.