Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. How I Can Print a File ?

How I Can Print a File ?

Scheduled Pinned Locked Moved Visual Basic
questioncsharphelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yadav A Kumar
    wrote on last edited by
    #1

    Help me. How can i print a word document (e.g. one.doc) by clicking on a Click event of a Button in VB.Net ?

    Annu Yadav

    V I 2 Replies Last reply
    0
    • Y Yadav A Kumar

      Help me. How can i print a word document (e.g. one.doc) by clicking on a Click event of a Button in VB.Net ?

      Annu Yadav

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      You can try this one: http://support.microsoft.com/kb/306346/en-us?spid=2530&sid=251[^]

      Vasudevan Deepak Kumar Personal Homepage Tech Gossips

      1 Reply Last reply
      0
      • Y Yadav A Kumar

        Help me. How can i print a word document (e.g. one.doc) by clicking on a Click event of a Button in VB.Net ?

        Annu Yadav

        I Offline
        I Offline
        IqbalVB
        wrote on last edited by
        #3

        You can use this, and change the filepath as you need: Private printFont As Font Private streamToPrint As StreamReader Private Shared filePath As String -------------------------------------------------- ' 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) ' Iterate over the file, printing each line. 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 ------------------------------------------ ' Print the file. Public Sub Printing() Try streamToPrint = New StreamReader(app_path & "\data.txt") Try printFont = New Font("Arial", 10) Dim pd As New PrintDocument() AddHandler pd.PrintPage, AddressOf pd_PrintPage ' Print the document. pd.Print() Finally streamToPrint.Close() End Try Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub 'Printing ' This is the main entry point for the application. Public Shared Sub Main() Dim args() As String = System.Environment.GetCommandLineArgs() Dim sampleName As String = args(0) If args.Length <> 1 Then Console.WriteLine("Usage: " & sampleName & " ") Return End If filePath = args(0) End Sub add to your click event this: Private Sub btnprint_click(byval sender as object, byval

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups