1

I have two functions. 1st for creating a Debit Note and 2nd for creating Invoice. I call Debit Note Function first and then Invoice function. The content of both files appears to be Debit Note. However the file names seems to be correct for both the files.

When I call Invoice function 1st and then Debit Note function. The content of both the files appears to be Invoice and the file names seems to be correct for both the file.

PS: I am calling both the functions together.

$this->mpdf->setAutoTopMargin = 'stretch';
$this->mpdf->setAutoBottomMargin = 'stretch';
$this->mpdf->SetHTMLHeader($this->pdftemplate->Header());
$this->mpdf->SetHTMLFooter($this->pdftemplate->Footer());
$html = $this->pdftemplate->debitNote($debitNoteNo, $narration, $amount);
$this->mpdf->SetTitle("Debit Note");
$this->mpdf->SetAuthor("Vikash");
$this->mpdf->SetCreator("Vikash");
$this->mpdf->SetSubject($debitNoteNo);
$this->mpdf->WriteHTML($html);
$url = "/temp/dn/" . $debitNoteNo . ".pdf";
$this->mpdf->Output($url, "F");




$this->mpdf->setAutoTopMargin = 'stretch';
$this->mpdf->setAutoBottomMargin = 'stretch';
$this->mpdf->SetHTMLHeader($this->pdftemplate->Header());
$this->mpdf->SetHTMLFooter($this->pdftemplate->Footer());
$html = $this->pdftemplate->invoice($invoiceNo, $narration, $amount);
$this->mpdf->SetTitle("Invoice");
$this->mpdf->SetAuthor("Vikash");
$this->mpdf->SetCreator("Vikash");
$this->mpdf->SetSubject($invoiceNo);
$this->mpdf->WriteHTML($html);
$url = "/temp/invoice/" . $invoiceNo . ".pdf";
$this->mpdf->Output($url, "F");

Can anyone help me with this? Thanks for reading the question and your valuable answers.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vikash Kumar
  • 41
  • 1
  • 5

1 Answers1

2

As I have noted in the issue at github, the safest way is to create a separate mPDF instance for each generated file.

Finwe
  • 6,372
  • 2
  • 29
  • 44
  • 1
    Yes sir. Creating a separate instance of mPDF solved the problem. – Vikash Kumar Jun 15 '17 at 05:28
  • How you created the separate instance. I am generating data using a loop, after the output, I unset the mdf obj and reinitialize it, but it did not work for me. – Hadayat Niazi Feb 28 '21 at 17:11
  • @HadiNiazi If you have problems with a particular use case, create a new Stack Overflow question with your reproducible code example and its results. – Finwe Feb 28 '21 at 17:37
  • Already created, please have a look at it. https://stackoverflow.com/questions/66410067/generating-pdf-using-mpdf-how-can-i-generate-multiple-pdf-in-php/66410092#66410092 – Hadayat Niazi Feb 28 '21 at 17:39