Skip to content

Print Preview a String

Michael

Asked May 7, 2008, 10:49 AM EDT1 answer
Share
LinkedInX
I need a simple way to just send a string to the Print Preview document. I don't care about fonds, sizes, any of that. I just want to send vanilla text to a print preview window.

I have this:
Dim printPreviewDialog1 As New PrintPreviewDialog() ' instantiate new print preview dialog
printPreviewDialog1.Document = PrintMeString
printPreviewDialog1.ShowDialog() ' Show the print preview dialog


Which is wrong, because PrintMeString is a String. Everything I found online is way too complictaed for what I want  to do. Any ideas?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0

    print preview works just like print.  you need to assign a PrintDocument control to the print preview dialog.  you need to handle the PrintPage event handler.  You need to draw your string in the PrintPage event handler with a font.

    e.Graphics.DrawString(myString, ...)

    There are ways to print text directly to the printer using a print driver, but it requires PInvoke to call directly to the printer,and yes, this is efficient but much more complicated with .NET.  It requires understanding the lower level print calls in the Windows SDK.  If you are interested, however, there is article by microsoft on the topic:

    http://support.microsoft.com/Default.aspx?kbid=322091

    0