3

I've created a PrintDocument in C#, I can print it, but now I want to save it to a file. Is it possible to save it as a word document?

Peter Bennett
  • 31
  • 1
  • 1
  • 3
  • Using a virtual printer? Like cups-pdf in linux or doPDF for windows? Now seriusly, printing is just glorified drawing. With that in mind, you could port your code to create a PNG. [I know, you want a word document]. How about you create an HTML file that uses javascript to call the printer dialog, and then you can open it in both the browser (to print) or word (to edit)? – Theraot Jun 17 '12 at 07:17
  • @Peter, please read my answer comments and vote accordingly.thanks – Yusubov Jun 19 '12 at 12:54

2 Answers2

4

Depending on your intent, this might be useful:

If your goal is to reprint it at a later date this will work:

print_doc.PrinterSettings.PrintToFile = true;
print_doc.PrinterSettings.PrintFileName = "backup.prn";
RGroppa
  • 325
  • 2
  • 13
1

Look a the following reference: Microsoft.Office.Tools.Word Namespace

Another link to msdn documentation How to: Save Documents

Yusubov
  • 5,815
  • 9
  • 32
  • 69
  • Well yes it is drawing. There are lots of Graphics.DrawString(...) calls in my code and Graphics.DrawLine(...) etc. So these drawings are in a method public void Itinerary_PrintPage(object sender, PrintPageEventArgs ev) and then these drawings are on a PrintDocument object, which then I have displayed in the default PrintPreview dialog. There is the option to click the button to print from the print preview dialog. There isn't any choice to choose different printers or a virtual printer. – Peter Bennett Jun 17 '12 at 07:34
  • The page has data in it from a database, so it displays the data when it is generated. It's only a 1 page document. I am using fonts that are also in microsoft word. I was wondering if it is possible to use Microsoft.Office.Interop.Word, to just send it to word or just save it as a word document. – Peter Bennett Jun 17 '12 at 07:44
  • Your original question, says "Is it possible to save it as a word document?". I have provided a reference in my answer. let me know if it works? – Yusubov Jun 17 '12 at 19:41
  • 2
    Thank you @EIYusubov for your useful references. I now have an answer to my question: I don't think it is possible or it would be way too difficult or complicated to save it as a word document. I found a way to open microsoft word, send it some text, save the document to the hard drive and close word. I should have used this method from the beginning. I will have to throw out my existing code and start from scratch using this method. An alternative it to use iTextSharp, which allows you to create a PDF document. But still I would have to start from scratch. Anyway, not a big deal. – Peter Bennett Jun 19 '12 at 20:49
  • **But I wonder what else can you do with a PrintDocument besides printing it?** This reference is about PrintDocument and also has an example. [PrintDocument](http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument(v=vs.100).aspx) my document is constructed a similar way. – Peter Bennett Jun 19 '12 at 20:49
  • Great! I am glad that you find a way. – Yusubov Jun 19 '12 at 20:51