Print on Linux and Windows in Qt/C++

798 views Asked by At

I have pdf files and I want to print them on paper (I say this because 'print' usually refers to pass the content generated to pdf file).

On Linux, I use system calls to CUPS passing the name of the file as an argument, but on Windows, this is not possible. I began to read about printing on Windows with C++, but I have to use proprietary libraries, and I don't want to use it for now (only last resource).

I read about QPrinter and other classes, but how can I use this class or other related to print pdf files? Does another thing print the pdf files exist?

1

There are 1 answers

1
pinkboi On

If your aim is to be able to print on the commandline just like you do in linux, you can install cygwin with lpr and ghostscript and that will probably allow you to print pdf files. Windows also has a built-in lpr that you can install. This isn't cups but should allow command-line printing.

If you want to do everything in C++ (which will require recompiling for each system), then you can use Qt with poppler. You can make a Qt app that just runs on the commandline, uses poppler to load the specified pdf into a QWidget, then make a QPrinter to print the contents of that widget. I have used invisible widgets before for printing so I know that's doable. But I'd make sure I've exhausted other options before getting my hands dirty making a new tool.