Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to print files #10

Open
tommed opened this issue Nov 1, 2018 · 8 comments
Open

Ability to print files #10

tommed opened this issue Nov 1, 2018 · 8 comments

Comments

@tommed
Copy link

tommed commented Nov 1, 2018

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!

@alexbrainman
Copy link
Owner

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

@tommed
Copy link
Author

tommed commented Nov 2, 2018

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.

@tommed
Copy link
Author

tommed commented Nov 2, 2018

...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?

@alexbrainman
Copy link
Owner

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 AddJob accepts 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 WritePrinter require you to call StartPagePrinter each 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

@tommed
Copy link
Author

tommed commented Nov 3, 2018

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

@alexbrainman
Copy link
Owner

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

@ghost
Copy link

ghost commented Dec 1, 2018

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.

@jadefox10200
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants