Printing doc, docx, pdf, rtf and txt files from C# to network printer

0

I am required to print a file, of set formats (doc, docx, pdf, rtf and txt), to a software network printer, however I cannot find a way of printing these documents easily.

I have already tried File.Copy(), but this fails - the printer wouldn't handle the job. I tried this method to an actual printer and got garbled text out, so that's obviously not going to work.

I've also tried Word Interop, however I've had a lot of trouble even trying to get that to work, with DCOM exceptions being thrown all over the place. I'm not going to attempt this path any further.

var word = new Microsoft.Office.Interop.Word.Application { Visible = false };
var doc = word.Documents.Open(file.FullName, Visible: false);
doc.Application.ActivePrinter = @"\\server01\printer01";
doc.PrintOut(Pages: "1");
doc.Close();
break;

^ Fails on line one with the following error:

"Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))."

I haven't tried Process.Start using the Print verb, as you can't seem to specify a specific printer.

How can I handle printing these files easily, preferably without having to purchase third-party software?

c#
printing
asked on Stack Overflow Jun 12, 2018 by James Hyde

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0