Getting Started with Pyrinter¶
Install Pyrinter¶
install pyrinter using pip:
$ pip install pyrinter
printer utils¶
find out about your printers data
first of all import the module:
>>> from pyrinter import printer_utils
now you can get all the printers names using the get_all_printers function:
>>> printer_utils.get_all_printers()
['printer 1', 'printer 2', 'PDFCreator', 'Microsoft Print to PDF']
you may also check for the default printer name using the function get_default_printer:
>>> printer_utils.get_default_printer()
'PDFCreator'
Document¶
To print a document, the first thing you should do is create the Document:
>>> from pyrinter import Document
>>> doc = Document()
the Document.__init__ method gets 2 parameters:
name- the name of the document by default -'My Document'page_size- the size of the paper in inches (for A4 -(8.3, 11.7)) default is A4
now you can add text to your doc:
>>> doc.add_text("Hello World")
the Document.add_text method gets 4 parameters:
text- the text that will add to the documentfont- the Font we are printing with see Font for more info, by default Arial 12 normalpage- the page’s index to print in, by default create new page and add the text to this pagerect- the rect to print on in (tuple of 4 floats) in the page, by default will be 0.75 inches margin now we want to print the document
Printer¶
import the printer class and create instance of it:
>>> from pyrinter import Printer
>>> printer = Printer()
the Printer.__init__ method gets 1 parameter:
name- the name of the printer, must be one of theprinter_utils.get_all_printers()by default will beprinter_utils.get_default_printer()
now to print the doc
>>> printer.print_doc(doc)
the Printer.print_doc gets 1 parameter:
doc- the Document to print