1

Hi so i have a code where it supposed to print out hardcopy of a pdf documents. Issue is i got said error when trying to print it when i set the path using ip/url.

def printInvoice(inv_id):
    _filepath = "http://192.168.0.72:8000/AR/invoice/"+inv_id+".pdf"    
    print(_filepath)
    printTheFile(_filepath)

def printTheFile(_file):
    currentprinter = win32print.GetDefaultPrinter()
    win32api.ShellExecute(0, 'print', _file, None, ".", 0)
    time.sleep(1)
    os.system("TASKKILL /F /IM Acrobat.exe")

inv_id = "INV2204-001"
printInvoice(inv_id)

If i set the path to just print it out directly from the script folder like "AR\\invoice" it works fine

Anyway, i make the folder available by using python -m http.server which makes it also available to be access on browser.

The goal is to make it able to work on multiple devices and print the pdf over the internet from one device that stores the docs.

blurryrox
  • 41
  • 6
  • 1
    [Read this](https://stackoverflow.com/questions/12626918/pythons-win32api-only-printing-to-default-printer) and [this](https://stackoverflow.com/questions/50365451/in-shellexecute-how-to-specify-print-parameters-like-page-range-tray-etc) – Dean Van Greunen May 08 '22 at 16:44
  • 1
    @DeanVanGreunen i don't know how that helps me? those link you gave is about printing parameters like selecting printer which i don't have any problem with. those code i use works fine if i set the path to my project folder, but problem occurred when i use IP address/URL in the path which makes me thinks my pathing format maybe wrong? – blurryrox May 08 '22 at 16:59
  • 1
    you may need to download the file, and then send it to the printer via a fully qualified local path – Dean Van Greunen May 08 '22 at 17:20
  • 1
    i guess it's better to use something like onedrive to sync filse instead of downloading it using code to make it available locally? – blurryrox May 09 '22 at 00:58
  • well its a workaround for silent printing, that's why i killed acrobat. i'll read about it but my aim is also to make able to print via internet, not just intranet – blurryrox May 09 '22 at 03:00

0 Answers0