none
Code for my Print To File button RRS feed

  • Question

  • I don't want to use the Print dialog but like the Print To File option.

    Would like to add that to the dialog box I create but don't know how to program it.

    Can you point me to (or supply) an example of the code needed?

    Monday, September 25, 2017 4:42 PM

Answers

  •  

     What are you trying to print,  plain text,  a picture,  rich text,  or ????

     

    Just trying to do what the print dialog does. I believe what is does is let you pick a file when you print; instead of sending the output to a printer. I don't believe it cares what the file type is.

     There is the PrintDocument Class which you can set up to print to a file.  You just need to set it's PrinterSettings.PrintToFile Property to True and supply the full filename for the printed document to the PrinterSettings.PrintFileName Property.  However,  you will need to handle drawing the Text, Images,  or whatever yourself in the PrintDocument.PrintPage Event.  That is where it gets a bit more complex and you would need to know if it is a Plain Text,  Rich Text, an Image,  or something else.  They would all require different methods to draw them in the PrintPage event.  Some file types you would not be able to print this way at all and would have to use completely different ways like using the Process class and setting it's Verb property to "Print".  That will pop up the "systems" print dialog though.   So,  you can see why the contents of what is to be printed matters.  There is not a one size fits all as far as i know.


    If you say it can`t be done then i`ll try it

    • Marked as answer by scholarQ Tuesday, September 26, 2017 12:36 AM
    Tuesday, September 26, 2017 12:12 AM

All replies

  • I don't want to use the Print dialog but like the Print To File option.

    Would like to add that to the dialog box I create but don't know how to program it.

    Can you point me to (or supply) an example of the code needed?

     What are you trying to print,  plain text,  a picture,  rich text,  or ????

     What type of file do you want to print to,  xps document,  a Pdf document,  or ???


    If you say it can`t be done then i`ll try it

    Monday, September 25, 2017 8:28 PM
  •  

     What are you trying to print,  plain text,  a picture,  rich text,  or ????

     

    Just trying to do what the print dialog does. I believe what is does is let you pick a file when you print; instead of sending the output to a printer. I don't believe it cares what the file type is.
    Monday, September 25, 2017 11:11 PM
  •  

     What are you trying to print,  plain text,  a picture,  rich text,  or ????

     

    Just trying to do what the print dialog does. I believe what is does is let you pick a file when you print; instead of sending the output to a printer. I don't believe it cares what the file type is.

     There is the PrintDocument Class which you can set up to print to a file.  You just need to set it's PrinterSettings.PrintToFile Property to True and supply the full filename for the printed document to the PrinterSettings.PrintFileName Property.  However,  you will need to handle drawing the Text, Images,  or whatever yourself in the PrintDocument.PrintPage Event.  That is where it gets a bit more complex and you would need to know if it is a Plain Text,  Rich Text, an Image,  or something else.  They would all require different methods to draw them in the PrintPage event.  Some file types you would not be able to print this way at all and would have to use completely different ways like using the Process class and setting it's Verb property to "Print".  That will pop up the "systems" print dialog though.   So,  you can see why the contents of what is to be printed matters.  There is not a one size fits all as far as i know.


    If you say it can`t be done then i`ll try it

    • Marked as answer by scholarQ Tuesday, September 26, 2017 12:36 AM
    Tuesday, September 26, 2017 12:12 AM