Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Mar 04, 2019 2:45 pm

Hi,

I'm trying to create a document with printer settings black and white by default, so when the user opens the document and press print button this may be printed in black and white.

Code: Select all
           
var documentPath = "C:\document.docx";

Spire.Doc.Document doc = new Spire.Doc.Document(documentPath);

doc.PrintDocument.PrinterSettings.DefaultPageSettings.Color = false;

MemoryStream stream = new MemoryStream();
doc.SaveToStream(stream, Spire.Doc.FileFormat.Docx);

// return stream.ToArray()


This code is inside a function, and returns a byte[] because i'm using this in server side on a apsx page, and this file is going to be sent to the client.

The problem is when the user opens the document and tries to print, the document is being printed with color.

Regards,
JP.

Prata
 
Posts: 3
Joined: Mon Mar 04, 2019 2:34 pm

Tue Mar 05, 2019 7:19 am

Hello,

Thanks for your post.
Please kindly note that the property (doc.PrintDocument.PrinterSettings.DefaultPageSettings.Color = false;) is a setting for printer but not for the Word document. After setting this property, there is no problem if sending document to the printer and printing directly. However, here you saved the document to a stream, actually this setting cannot be applied in the saved stream. Thus, the document was printed with color when printing the stream directly on the client. You need to set the property before printing on the client. Hope you can understand.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Wed Mar 06, 2019 3:39 pm

Hi,

Thank you for this reply.

As i can understand, this means that i cannot set (doc.PrintDocument.PrinterSettings.DefaultPageSettings.Color = false;) and then save to stream, but if i SaveToFile (in local folder) and then open the document and click in print button it doesnt work either.
What do you mean with
(...) there is no problem if sending document to the printer and printing directly (...)
, i need to call a method directly in code and send this document to printer queue?
The solution i want is to download the document from a webpage, and then open and click print button or somehow send it to printer queue from this webpage.

Regards,
JP.

Prata
 
Posts: 3
Joined: Mon Mar 04, 2019 2:34 pm

Thu Mar 07, 2019 2:56 am

Hello,

Sorry to make you confused. Firstly, whether you save the Word document to stream or to file, this setting can not be saved since it is for printer but not for the Word document. Secondly, "there is no problem if sending document to the printer and printing directly" that means this setting only takes effect if you print directly before saving the document. Finally, our Spire.Doc supports printing directly by doc.PrintDocument.Print();. And based on your solution, you could try the following code to download the document from a webpage, open and send it to printer for printing directly. If there is any question, just feel free to contact us.
Code: Select all
 using (WebClient webClient = new WebClient())
 { 
     //download file
     byte[] data = webClient.DownloadData("YourFilePath");
     using (MemoryStream mem = new MemoryStream(data))
     { 
         //open file
         Document doc = new Document();
         doc.LoadFromStream(mem, Spire.Doc.FileFormat.Docx);
         doc.PrintDocument.PrinterSettings.DefaultPageSettings.Color = false;
         //send file to default printer and print directly
         doc.PrintDocument.Print();
         doc.Close();
     }
 }

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Thu Mar 07, 2019 5:51 pm

Hi,

Thank you for your reply.
Now i have understand how this works, and what i was trying to do is printing after saving the document. :D

Regards,
JP.

Prata
 
Posts: 3
Joined: Mon Mar 04, 2019 2:34 pm

Fri Mar 08, 2019 2:08 am

Hello,

Thanks for your quick feedback. Just feel free to contact us if you need other assistances in the future.
Have a nice day!

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc