-1

All online search relates printing a df in console. Does python have the capability to print a df directly (without saving it as a file in windows) ?

To clarify - It should not be saved as a pdf/excel/any other file. Can we print (to paper) the dataframe directly?

As far as my exploration, I think we cannot print anything (string / graph / etc) directly from Python. We might always have to do it via a file (doc/excel/pdf). Please correct me if wrong.

Harsh Khad
  • 99
  • 1
  • 7
  • Does this answer your question? [Export Pandas DataFrame into a PDF file using Python](https://stackoverflow.com/questions/33155776/export-pandas-dataframe-into-a-pdf-file-using-python) – Josh Aug 17 '20 at 05:32
  • `Can we print (to paper) the dataframe directly?` What does it mean? Can I think you need to send print job to printer and it can print directly without saving it as a file? – Strive Sun Aug 18 '20 at 03:18
  • Exactly. That is what I am wondering if its possible.? – Harsh Khad Aug 18 '20 at 06:31

1 Answers1

1

You can use win32print module.

Please read the following documents first:

Applications that print create a printer device context (DC). When an application creates a printer DC, the spooler performs necessary tasks such as determining the location of the required printer driver and then loading that driver. The print spooler also determines the data type used to record the print job.

The print spooler supports the following data types:

  • Enhanced metafile (EMF).
  • ASCII text.
  • Raw data, which includes printer data types such as PostScript, PCL, and custom data types.

Custom data types can be added to the spooler by installing additional printer drivers and print processors. A print job is a document stored internally and encoded by using one of the supported data types, and a print job may contain one or more pages of output.

The spooler deletes these files when the job has successfully printed.

It is indeed possible to print jobs directly without saving them as files, because the spooler will delete these files directly after printing.

Related: https://stackoverflow.com/a/14615664/11128312

Strive Sun
  • 5,988
  • 1
  • 9
  • 26
  • @Harsh Khad Hi, if the answer is useful to you, don't forget to mark it. This can be beneficial to other community members reading this thread. [How to accept an answer?](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) – Strive Sun Aug 20 '20 at 01:41
  • Thanks for the detailed info. But looks like printing directly is way more complicated than printing via a file (with formats, layouts, etc. all easily handled). – Harsh Khad Aug 22 '20 at 11:30