How to print PDF’S with python by checking if the print was successful?

Asked

Viewed 678 times

0

Is there any way to implement a python printing routine where it is possible to verify that the file has been printed successfully? I’ve tried using java with PDFBOX, but I couldn’t find a way to do that. Is there any other library that provides this feature?

  • There’s no one way. Pdfs are simpler than txt - but take a look at my answer here to get an idea: https://answall.com/questions/65072/como-imprimir-um-arquivo-txt-em-python/65122#65122

  • my need is to print without user intervention @jsbueno

  • I need to know the operating system to give more tips. Windows?

  • Yes, Windows...

1 answer

3

As it is in my answer on How to print a txt file in Python , printing is not a feature of any language, and yes, it depends on interaction with the operating system.

I think a good way, regardless of the system, can be to use Python to call the "Ghostscript" in a sub-process: it can render the PDF to the Windows API or directly to the printer.

The "if the print is wrong" check depends on the print driver - and then you really need to talk to the operating system API. I did a quick search and fortunately it seems that someone has encapsulated the main features of the Windows API in a "win32print" Python module - take a look here: http://timgolden.me.uk/pywin32-docs/win32print.html

With that you could use the Ghostscript to render the PDF to data printable by Windows (I forgot the name of the internal format now), and use this win32print to send this resulting data to the printer. Some printer models can accept PDF files directly (it is difficult to know these days, as the operating system’s print stack manages everything), if any, your solution can work without the Ghostscript part - only with win32print.

The other forms of printing - using libraries that have Wrappers on top of the Win32api, such as gtk+ and Qt, would require interaction with the user (they will open the standard windows print dialog at some point). It is also possible to combine this with the Pyautogui to press the "start printing" buttons automatically - but it would be more appropriate only if your software was already desktop (and is still a scam).

Unfortunately there is no short, simple answer - it’s going to take a lot of dedication. If you decide to hold down one of the paths I’ve indicated and start making some code, feel free to ask other questions.

  • Thanks for your help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.