[PyQt] Re: Thermal Printer on QPrinter
dboddie at trolltech.com
dboddie at trolltech.com
Wed Jan 21 14:21:44 GMT 2009
On Wednesday 21 January 2009, Eduardo Willians wrote:
> > printer.setPaperSize(QSizeF(79, 72), printer.Millimeter)
>
> David, I thank you for your help. Receipt printers use spool-paper, so
> paperSize must be something like 72mm x "the size of the printing".
OK, but you might want to try a fixed height to start with, just to see what
happens.
> Based on your suggestion I tried the following:
>
> printer.setPaperSize(QSizeF(72, printer.Custom), printer.Millimeter)
> printer.setPaperSize(QSizeF(72, printer.Auto), printer.Millimeter)
>
> And also inversed:
>
> printer.setPaperSize(QSizeF(printer.Custom, 72), printer.Millimeter)
> printer.setPaperSize(QSizeF(printer.Auto, 72), printer.Millimeter)
>
> But none of these worked.
printer.Auto evaluates to a value of 6 (QPrinter.Auto is a value provided
by QPrinter.PaperSouce) and printer.Custom evaluates to a value of
30 (QPrinter.Custom is a value provided by QPrinter.PaperSize):
http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qprinter.html#PaperSource-enum
http://doc.trolltech.com/4.5/qprinter.html#PaperSize-enum
So, you might get unexpected results using those values. I suggest trying to
determine the expected height of the printout somehow and pass that as the
height argument to QSizeF. I guess you face the opposite problem to most
people trying to print documents - instead of needing a sequence of fixed
size pages, you need just one very tall page.
Perhaps Eric4 just sends characters to a printer, as someone suggested for a
solution to your problem. This might be one way to achieve what you want,
though you miss out on the abstraction provided by Qt if you do this.
I experimented a little with printing to custom paper sizes, modifying your
original code to create a PDF file (using Qt 4.4 because that provides the
setPaperSize() method that we need):
from PyQt4.QtCore import QSizeF
from PyQt4.QtGui import *
import sys
app = QApplication(sys.argv)
printer=QPrinter()
printer.setFullPage(True)
printer.setPaperSource(printer.Auto)
doc=QTextDocument("Hello World!")
printer.setOutputFormat(printer.PdfFormat)
printer.setOutputFileName("temp000.pdf")
printer.setPaperSize(QSizeF(72, 144), printer.Millimeter)
doc.print_(printer)
This could be used as the basis for what you need if, after removing the
setOutputFormat() and setOutputFileName() calls, it actually sends correct
output to the printer. Of course, there's the issue of the automatic page
numbering, but that's another issue...
David
More information about the PyQt
mailing list