-1

I am working on continuous printing of receipts on a thermal printer. To do this I need to generate PDF to send to printer. Printer uses 58mm roll of paper.

If the content is broken down into multiple pages of fixed height, last page will often have a lot vertical blank space at the end. The printer will then just unnecessarily push out a lot of blank paper at the end. I then tried cropping and merging pages into single page, but this is highly inefficient (takes at least 4 seconds which is not acceptable).

Only solution I can think of is to generate a PDF with all content on a single page with page width of 58mm and page height dynamically set based on generated content.

I tried using PyPDF2, reportlab and few other libraries, but all the libraries I tried require setting exact page width before even putting elements into place.

Any ideas how can this be done?

Djuka
  • 505
  • 5
  • 19

1 Answers1

0

Your question or what you want to do is uselessly burdensome without taking advantage of the features of the thermal receipt printer, so I recommend rethinking and switching to character code printing.

If you still want to continue the way you've been doing, these articles may be helpful.
text printed twice on the same page
Resize pdf pages in Python

For example, each time you add a PDF, you can create a blank page that totals the height of the existing PDF and the PDF to be added, and then repeatedly merge both PDFs into the blank page to dynamically expand the page height.


Below is the initial answer.
I will leave it as information to utilize the features of the thermal receipt printer.


After all, the printer's graphic data buffer is finite, so you can't do what you want.

The size of the buffer depends on the printer, so please read the specifications of the printer you are using carefully.

Image data must be created by separating each printer's maximum buffer size.


Response to comment:

It is probably a vendor-made device driver or library that adjusts the characteristics of the printer and the requirements of the OS.

It may be possible if you use a device driver made by such a vendor.
In other words, the vendor's device driver is doing the processing internally by passing as pointed out above, making the application appear to support long pages.

However, if you use the ESC/POS control sequence directly, or if you use a generic library that doesn't care about it, that won't happen.


By the way, if the print content is not a PDF or image and you do not need decorations like printing on a document printer of a desktop system, and you limit the printing method to only the range of the printer font, you can print up to the length of the paper.

In short, it is good if there is no need to expand the printed contents as graphic data.

kunif
  • 4,060
  • 2
  • 10
  • 30
  • I manually created a large PDF file with single page and fixed height of 50cm and some test data. Printer has no problem printing this. Printing is done over driver provided by the manufacturer. I just send PDF bytes to the device. – Djuka Feb 24 '22 at 11:27