Thanks all for the help on this but i have found it to difficult and decided to print from a richtextbox with a excellent Link Hack provided in this thread
Hope it can help someone elseCode:Option Explicit On Option Strict On Imports System.IO Imports System.Drawing.Printing Public Class Form1 Inherits System.Windows.Forms.Form Dim sw As IO.StreamWriter Dim sr As IO.StreamReader Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'read a text file into richtextbox Dim myOutput As StreamReader Dim sValues As String myOutput = New StreamReader("C:\StickFrameExpress\Jobs\adadad.txt") sValues = myOutput.ReadToEnd Me.RichTextBox2.Text = sValues myOutput.Close() End Sub Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click Me.PrintDocument1.DefaultPageSettings.Landscape = True If PrintDialog1.ShowDialog = DialogResult.OK Then 'showDialog method makes the dialog box visible at run time With Me.PrintDocument1 .PrinterSettings.DefaultPageSettings.Landscape = True .Print() End With End If End Sub Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage 'PrintPage is the foundational printing event. This event gets fired for every ' page that will be printed Static intCurrentChar As Int32 ' declaring a static variable to hold the position of the last printed char Dim font As New Font("Courier New", 8) ' initializing the font to be used for printing Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32 With PrintDocument1.DefaultPageSettings .Landscape = True ' initializing local variables that contain the bounds of the printing area rectangle PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right ' initializing local variables to hold margin values that will serve ' as the X and Y coordinates for the upper left corner of the printing ' area rectangle. marginLeft = 20 marginTop = 10 ' X and Y coordinate End With Me.PrintDocument1.DefaultPageSettings.Landscape = True If PrintDocument1.DefaultPageSettings.Landscape Then Dim intTemp As Int32 intTemp = PrintAreaHeight PrintAreaHeight = PrintAreaWidth PrintAreaWidth = intTemp ' if the user selects landscape mode, swap the printing area height and width End If Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height) ' calculating the total number of lines in the document based on the height of ' the printing area and the height of the font Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight) ' initializing the rectangle structure that defines the printing area Dim fmt As New StringFormat(StringFormatFlags.LineLimit) 'instantiating the StringFormat class, which encapsulates text layout information Dim intLinesFilled, intCharsFitted As Int32 e.Graphics.MeasureString(Mid(RichTextBox2.Text, intCurrentChar + 1), font, New SizeF(PrintAreaWidth, PrintAreaHeight), fmt, intCharsFitted, intLinesFilled) ' calling MeasureString to determine the number of characters that will fit in ' the printing area rectangle e.Graphics.DrawString(Mid(RichTextBox2.Text, intCurrentChar + 1), font, Brushes.Black, rectPrintingArea, fmt) ' print the text to the page intCurrentChar += intCharsFitted Me.Close() End Sub End Class




Reply With Quote