Ability to print files
Bypassing the printer driver and using the Windows Printer Spool API allows you to pass in a file path and print the file however it should be handled (covers PDF, DOCX, XLSX, txt files which would usually need different approaches when processed by the driver).
Particularly the AddJob function allows a job with a file path.
It feels like the last little part missing in this brilliant library!
Thank you for nice words about my work.
I googled AddJob usage, and I cannot find any good examples. This package uses WritePrinter Windows API. Why do we also need AddJob? What does AddJob do, that cannot be done by WritePrinter?
Thank you.
Alex
No worries, appreciate this library, it may prove very useful.
My understanding of WriterPrinter is the byte array that is fed in is interpreted by the printer based on the pDocInfo.pDatatype you specify when calling StartDocPrinter. Therefore you can't just feed it the bytes of a file as it won't know how to print the contents of a PDF or a DOCX unless they are converted into printer instructions?
Whereas AddJob accepts a path to a file so it'll print anything you give it.
This may be a misunderstanding on my part of the way WritePrinter works rather than a feature request; my aim is to be able to print any arbitrary file (like this app) the user wishes to print without knowing anything about the underlying type - just as you can from the Windows Print Dialog.
...In addition, doesn't WritePrinter require you to call StartPagePrinter each time there's a page break too? Obviously that would require you to understand the file (e.g. PDF/DOCX) and the number of pages held in the file?
Therefore you can't just feed it the bytes of a file as it won't know how to print the contents of a PDF or a DOCX unless they are converted into printer instructions?
That is how I understand WriterPrinter usage too.
Whereas
AddJobaccepts a path to a file so it'll print anything you give it.
Sure. But nowhere does it say that the file you are providing can contain PDF or DOCX either. Am I wrong?
my aim is to be able to print any arbitrary file (like this app) the user wishes to print without knowing anything about the underlying type
I am not familiar with this software. I would not know how it works.
.In addition, doesn't
WritePrinterrequire you to callStartPagePrintereach time there's a page break too?
You can do that. Or you could insert 'page break' in between bytes you send to the printer. Most printers support form feed - https://en.wikipedia.org/wiki/Page_break
Alex
Ok... let me amend my request sightly. How can I print any arbitrary file using your library please? Your example does not work with files which aren't plain/text-based.
Many thanks, -Tom
How can I print any arbitrary file using your library please?
I don't think it is possible. I created this package to print text files - all printers I used print my text files with no problem. I have not tried to print PDF or DOCX files.
Alex
i would also like to be able to print images and pds's. Hope this somehow gets resolved. Its kind of weird that golang does not have backed in support for this in many ways i feel - dont mean to grumble but had to say it.
As a note, I have been using code from this library to print PDFs for quite some time now. However, I am using a xerox workcenter 7435 which does understand PDF on its own. It may be easier to find a driver for your printer to read the bytes and convert it to print PDF.