Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I ask Windows to print a document?

I want to (programmatically) print documents of various types, by asking Windows to do it (using the default associated application). How can I do this (in .NET or C++/Win32 API)?

For example, if I have MS Office and Acrobat Reader installed on the machine, PDF files should be printed by Acrobat Reader, and DOC files should be printed by MS Word. But if I don't have MS Office installed, DOC files should be printed using Wordpad, or OpenOffice.org Writer if the latter is installed, or whatever application is currently the default association for that type of files.

like image 680
Hosam Aly Avatar asked Oct 08 '09 13:10

Hosam Aly


People also ask

How can I get documents printed?

To start, right-click your Windows Start menu button and click the “Event Viewer” option. The Event Viewer will allow you to view a list of previously printed files, but you'll need to set Windows to begin logging your long-term printer history first.

How do I get to the print dialog box?

Alternatively, click (Down arrow) of the Start Printing button in the Edit and Print Clips screen and select Print Settings.... The Print Settings dialog box appears. The Print dialog box is used as an example in the following descriptions. Each setting item is the same for Print Settings dialog box.

How can we print a document from window?

Click File > Print. Under Settings, choose the color printing option, and any other options you want, and click the Print button.


2 Answers

Try using the ShellExecute function.

For example, in C:

 ShellExecute(my_window_handle, "print", path_to_file, NULL, NULL, SW_SHOW);
like image 105
Josh Kelley Avatar answered Sep 29 '22 10:09

Josh Kelley


Call ShellExecute. Use "print" for the lpOperation parameter.

like image 35
Rob Kennedy Avatar answered Sep 29 '22 11:09

Rob Kennedy