Printing with a .NET Application

J

Joe Cool

I have written a fairly simple application for home use that I would
like to add a print function to. The output may or may not contain
graphic images that are stored in JPG format in a SQL database. I can
probably figure out how to do it if I knew where to start. I have
looked briefly at the Microsoft.Office.Interop.Word namespace, but it
looks like the word document file already has to exist. I will need to
create the document to print on the fly based on contents from the
database for the selected item being printed.

Any help would be appreciated.
 
S

Scott Seligman

Joe Cool said:
I have written a fairly simple application for home use that I would
like to add a print function to. The output may or may not contain
graphic images that are stored in JPG format in a SQL database. I can
probably figure out how to do it if I knew where to start. I have
looked briefly at the Microsoft.Office.Interop.Word namespace, but it
looks like the word document file already has to exist. I will need to
create the document to print on the fly based on contents from the
database for the selected item being printed.

You can use the PrintDocument class. Basically, you create a
PrintDocument object, and handle the PrintPage event to draw on a
page. Check out the documentation for more information, including an
example:

http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx
 
J

Joe Cool

You can use the PrintDocument class.  Basically, you create a
PrintDocument object, and handle the PrintPage event to draw on a
page.  Check out the documentation for more information, including an
example:

http://msdn.microsoft.com/en-us/library/system.drawing.printing.print...

I looked into the PrintDocument Class. The example code uses a .TXT
file and the streamreader in the PrintPage event handler is reading
the .TXT file line by line. Would I do a Word document the same way?
And just how would I create the Word document to print on the fly? The
example assume a .TXT file that already exists.
 
F

Family Tree Mike

Joe said:
I looked into the PrintDocument Class. The example code uses a .TXT
file and the streamreader in the PrintPage event handler is reading
the .TXT file line by line. Would I do a Word document the same way?
And just how would I create the Word document to print on the fly? The
example assume a .TXT file that already exists.

Do you have a strong desire to go to an MS Word document?

If so I would work on that first as a general export capability. Next
reuse the code to print a document based on that format by hiding the
filename selection and simply doing Process.Start() to send it to the
printer with StartInfo.Verb = "Print" and StartInfo.FileName = your temp
file.

If you have no other reason to go to MS Word, then using the
PrintDocument class is not that difficult. On the PrintPage event, you
just need to use the page graphics to determine where the images go, and
whether multiple ones fit on one page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top