none
How to print…. And create a soft copy

    Question

  •  

    How to write a print application which prints and creates the copy in Microsoft word or HTML file?

    I have written good print application in Vb.net using the rich Print and Drawing Objects in .Net Framework.

    I would like to create one soft copy whenever I do print.

    What is the best approach?

    Thank you,

    Smith

     

    .Net Framework 2.0

     

    Friday, November 02, 2007 12:35 AM

Answers

  • You could draw each page to a bitmap in the PrintPage event.  You could also print a copy to the XPS Document Writer. 
    Friday, November 02, 2007 6:00 PM
  • Gish,

     

    PrintDocument.PrintPage Event occurs when the output to print for the current page is needed. It is in namespace of System.Drawing.Printing that is supported in .NET Framework 2.0, 1.1 and 1.0.

     

    The following code snippet shows you the example for the PrintPage event:

     

    Code Block

        ' The PrintPage event is raised for each page to be printed.

        Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)

            Dim linesPerPage As Single = 0

            Dim yPos As Single = 0

            Dim count As Integer = 0

            Dim leftMargin As Single = ev.MarginBounds.Left

            Dim topMargin As Single = ev.MarginBounds.Top

            Dim line As String = Nothing

     

            ' Calculate the number of lines per page.

            linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

     

            ' Print each line of the file.

            While count < linesPerPage

                line = streamToPrint.ReadLine()

                If line Is Nothing Then

                    Exit While

                End If

                yPos = topMargin + count * printFont.GetHeight(ev.Graphics)

                ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())

                count += 1

            End While

     

            ' If more lines exist, print another page.

            If Not (line Is Nothing) Then

                ev.HasMorePages = True

            Else

                ev.HasMorePages = False

            End If

        End Sub

     

     

     

    For futher information, you can also take a look at the following link on PrintEvent in MSDN:

     

    http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printdocument.printpage.aspx 

     

    Except that method, I would also provide you a more complicated example on the issue. This example would also call the Win32 API spooler function to send the types and other types of raw data to a printer. I hope that can provide you more ideas on this kind of problems:

     

    How to send raw data to a printer by using Visual Basic .NET

    Hope that can help you.
    Monday, November 05, 2007 3:58 AM

All replies

  • You could draw each page to a bitmap in the PrintPage event.  You could also print a copy to the XPS Document Writer. 
    Friday, November 02, 2007 6:00 PM
  • Is the two solution is possible with .Net Framework 2.0?

    Thank you,

    Smith

     

     

    Friday, November 02, 2007 9:44 PM
  • Gish,

     

    PrintDocument.PrintPage Event occurs when the output to print for the current page is needed. It is in namespace of System.Drawing.Printing that is supported in .NET Framework 2.0, 1.1 and 1.0.

     

    The following code snippet shows you the example for the PrintPage event:

     

    Code Block

        ' The PrintPage event is raised for each page to be printed.

        Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)

            Dim linesPerPage As Single = 0

            Dim yPos As Single = 0

            Dim count As Integer = 0

            Dim leftMargin As Single = ev.MarginBounds.Left

            Dim topMargin As Single = ev.MarginBounds.Top

            Dim line As String = Nothing

     

            ' Calculate the number of lines per page.

            linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

     

            ' Print each line of the file.

            While count < linesPerPage

                line = streamToPrint.ReadLine()

                If line Is Nothing Then

                    Exit While

                End If

                yPos = topMargin + count * printFont.GetHeight(ev.Graphics)

                ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())

                count += 1

            End While

     

            ' If more lines exist, print another page.

            If Not (line Is Nothing) Then

                ev.HasMorePages = True

            Else

                ev.HasMorePages = False

            End If

        End Sub

     

     

     

    For futher information, you can also take a look at the following link on PrintEvent in MSDN:

     

    http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printdocument.printpage.aspx 

     

    Except that method, I would also provide you a more complicated example on the issue. This example would also call the Win32 API spooler function to send the types and other types of raw data to a printer. I hope that can provide you more ideas on this kind of problems:

     

    How to send raw data to a printer by using Visual Basic .NET

    Hope that can help you.
    Monday, November 05, 2007 3:58 AM
  • Thank you very much.

    Smith

     

     

    Tuesday, November 06, 2007 1:44 AM