0

When using mPDF to generate a sales invoice PDF that aligns with a pre-printed form, the alignment is perfect on the first print after resetting the printer. However, when printing the same or any other sales invoice again, the alignment shifts, causing the printed content to misalign with the pre-printed form. This issue occurs even though the PDF preview before printing is correct and consistent for all invoices. Each page prints with a different alignment.

I am using a custom page size of 210mm x 290mm

I am using an Epson LQ-690 dot matrix printer. Is this problem happening because of the mPDF code, or is it a hardware issue? How can I solve this problem?

Below are the mPDF settings I am using:

$mpdf = new \Mpdf\Mpdf([
    'margin_header' => 0,
    'margin_footer' => 0,
    'margin_top' => 0,
    'margin_left' => 0,
    'margin_right' => 0,
    'margin_bottom' => 0,
    'format' => [210, 290], // Custom page size in mm (width, height)
    'default_font' => 'Myriad Pro',
    'default_font_size' => 10,
    'keep_table_proportions' => true, 
    'autoPageBreak' => true, 
    'shrink_tables_to_fit' => 1,
    'SetAutoPageBreak' => true,
    'setAutoTopMargin' => 'stretch', 
    'setAutoBottomMargin' => 'stretch', 
    'adjust_font_disparity' => true, 
]);

// Additional settings to ensure consistent margins
$mpdf->SetMargins(0, 0, 0);
$mpdf->SetAutoPageBreak(true, 0);
$mpdf->SetDisplayMode('fullpage');

$mpdf->SetHTMLHeaderByName('Header');
$mpdf->SetHTMLFooterByName('Footer');
$mpdf->SetTitle('INVOICE');
$mpdf->SetSubject('INVOICE');
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$mpdf->WriteHTML($htmlContent);
$mpdf->SetHTMLFooterByName('Footer');
ob_clean();
$mpdf->Output();

I need to understand whether this issue is caused by the mPDF code or if it's related to the printer hardware (Epson LQ-690 dot matrix printer). Additionally, I'm looking for guidance on how to resolve this issue to ensure consistent alignment across all prints.

5
  • Does it shift across the page, or down it? Does it shift once, or does it "walk" down (or across) the page by an amount on each invoice until you reset the printer? If it "walks", does it do so by the same amount each time? Is the movement related to the page content? Does the content actually fit on the page? I must say it seems that using a PDF library to print text directly to a dot matrix printer seems a complicated way of doing it, but then I can't think how else you'd send plain text out from PHP. Commented Aug 21, 2024 at 6:55
  • @droopsnoot Thanks for help. Only the vertical alignment of the whole PDF content is changing with each print. If I print the same PDF five times, the vertical alignment on each printout is different. Most of our PDFs are single pages, so the content fits within the page. There are only 1 to 10 lines on a single page. In the first print, the alignment is correct; in the second print, it moves down; in the third print, it again moves down; then it comes back to correct alignment. The vertical alignment changes each time with no specific measurement for the change. Commented Aug 21, 2024 at 8:04
  • Is the printer returning to the proper position every time the printout finishes? If you select to print to a virtual PDF printer on your client, does the output move around on that too? Commented Aug 21, 2024 at 9:47
  • @droopsnoot Yes, the printer returns to the proper position every time. I haven't tried printing to a virtual PDF printer. However, when I print the PDF from the browser, the PDF preview shows no vertical spacing issues. Every time I print, the PDF preview has the same vertical alignment. Commented Aug 22, 2024 at 5:27
  • @droopsnoot But when the print comes out, it has a different vertical alignment. I'm using continuous paper on an Epson LQ-690 dot matrix printer, and in the mPDF code, I use a custom width and height of 210mm x 290mm. Recently, I changed this to 210mm x 278mm and also applied this change to the printer settings. This adjustment has reduced the alignment issue, but there's still a slight vertical alignment issue on each print. Commented Aug 22, 2024 at 5:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.