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
  1. Home
  2. General Programming
  3. Visual Basic
  4. Printing text file in vb.net - Formatting issue

Printing text file in vb.net - Formatting issue

Scheduled Pinned Locked Moved Visual Basic
graphicshelpcsharpsales
11 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.
  • K kedarrkulkarni

    Hi, i create a text file in my code and i want to print the now. origianl file looks like /********* File Starts Here *************************** 9/22/2008 Name of the customer and details 10010 /********* File Ends Here *************************** But when i print this file in my project using following code...

    Dim pd As New PrintDocument
    Dim ps As new PageSettings
    ps.Landscape = False
    ps.Margins.Top = 0.116
    ps.Margins.Bottom = 0.116
    ps.Margins.Left = 0.116
    ps.Margins.Right = 0.116
    ps.PaperSize = New System.Drawing.Printing.PaperSize("A4", 210, 297)
    pd.DefaultPageSettings = ps

                        AddHandler pd.PrintPage, AddressOf pd\_PrintPage
    

    and using drawstring function of Graphics as ,

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

    the resulting printout looks like... /********* File Starts Here *************************** 9/22/2008 Name of the customer and details 10010 /********* File Ends Here *************************** problem is the first line gets overlapped with second one. i.e date is overlapping "Name of the customer and details" line. which is not actual case. (so, whole formatting of file is getting lost when i m printing in project but manual file print works fine). where i am missing something. or is it something to do with saize of paper?

    K Offline
    K Offline
    kedarrkulkarni
    wrote on last edited by
    #2

    Sorry folks.... Originas file is like /********* File Starts Here *************************** ____________________________________________________9/22/2008 _______________Name of the customer and details ________________________________________________________10010 /********* File Ends Here *************************** and print file format is /********* File Starts Here *************************** _____________________________________9/22/2008 _______________Name of the customer and details __________________________________________10010 /********* File Ends Here ***************************

    T 1 Reply Last reply
    0
    • K kedarrkulkarni

      Sorry folks.... Originas file is like /********* File Starts Here *************************** ____________________________________________________9/22/2008 _______________Name of the customer and details ________________________________________________________10010 /********* File Ends Here *************************** and print file format is /********* File Starts Here *************************** _____________________________________9/22/2008 _______________Name of the customer and details __________________________________________10010 /********* File Ends Here ***************************

      T Offline
      T Offline
      Thomas Stockwell
      wrote on last edited by
      #3

      I am still not understanding the exact error you are having. In the initial statement you speak of overlapping line segments, and then in the new post, the only problem i see is a smaller amount of underscores for the date and the other number (no overlapping lines). it could just be that the forum is not formatting it the way you are explaining it, but could you still clarify.

      Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my Blog

      K 1 Reply Last reply
      0
      • T Thomas Stockwell

        I am still not understanding the exact error you are having. In the initial statement you speak of overlapping line segments, and then in the new post, the only problem i see is a smaller amount of underscores for the date and the other number (no overlapping lines). it could just be that the forum is not formatting it the way you are explaining it, but could you still clarify.

        Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my Blog

        K Offline
        K Offline
        kedarrkulkarni
        wrote on last edited by
        #4

        Right thomas.. forum is not able to format the space at starting of line. so i have replaced space with underscore. so, consider underscores as spaces then u can see the diffrence between original file and printed version. the number of spaces in print is less than that of original. here note that, when i print file in notepad directly its giving proper print. but same file when i print through application, its minimizing the number of spaces that makes me beleive that its formatting or page setting issue in application. Any Help ?

        K 1 Reply Last reply
        0
        • K kedarrkulkarni

          Right thomas.. forum is not able to format the space at starting of line. so i have replaced space with underscore. so, consider underscores as spaces then u can see the diffrence between original file and printed version. the number of spaces in print is less than that of original. here note that, when i print file in notepad directly its giving proper print. but same file when i print through application, its minimizing the number of spaces that makes me beleive that its formatting or page setting issue in application. Any Help ?

          K Offline
          K Offline
          kedarrkulkarni
          wrote on last edited by
          #5

          I ressolved the issue..... For anyone who are intrested... When u try to print the file in vb.net with preceding space characters, then in print u dont get same number of spaces(actually number of spaces are same but width of total space gets reduced) To overcome this problem, u have to use font like "Courier New" which having same width for all characters. as ,

          Private printFont As Font
          printFont = New Font("Courier New", 10)

          e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _
          yPos, sFormat)

          The scenario is when positioning of printed string on paper does matter a lot.. Cheers !

          D T 2 Replies Last reply
          0
          • K kedarrkulkarni

            I ressolved the issue..... For anyone who are intrested... When u try to print the file in vb.net with preceding space characters, then in print u dont get same number of spaces(actually number of spaces are same but width of total space gets reduced) To overcome this problem, u have to use font like "Courier New" which having same width for all characters. as ,

            Private printFont As Font
            printFont = New Font("Courier New", 10)

            e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _
            yPos, sFormat)

            The scenario is when positioning of printed string on paper does matter a lot.. Cheers !

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #6

            That's because when you printed the test, you used a proportial spaced font. When you used Courier New, you started using a fixed space font. Proportial means that each character uses just the amount of space it needs to get rendered. For example, a 'W' needs more width than a '.' to render. In a fixed space font, every character uses the same amount of space when rendered, regardless of how much it actually needs.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            K 1 Reply Last reply
            0
            • K kedarrkulkarni

              I ressolved the issue..... For anyone who are intrested... When u try to print the file in vb.net with preceding space characters, then in print u dont get same number of spaces(actually number of spaces are same but width of total space gets reduced) To overcome this problem, u have to use font like "Courier New" which having same width for all characters. as ,

              Private printFont As Font
              printFont = New Font("Courier New", 10)

              e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _
              yPos, sFormat)

              The scenario is when positioning of printed string on paper does matter a lot.. Cheers !

              T Offline
              T Offline
              Thomas Stockwell
              wrote on last edited by
              #7

              Damn this dial-up and AOHell, I was just about to post the same solution you found not more than 5 minutes ago. Still glad you found the solution though :)

              Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my Blog

              1 Reply Last reply
              0
              • D Dave Kreskowiak

                That's because when you printed the test, you used a proportial spaced font. When you used Courier New, you started using a fixed space font. Proportial means that each character uses just the amount of space it needs to get rendered. For example, a 'W' needs more width than a '.' to render. In a fixed space font, every character uses the same amount of space when rendered, regardless of how much it actually needs.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008

                K Offline
                K Offline
                kedarrkulkarni
                wrote on last edited by
                #8

                yes dave. but can i use proportial spaced font and still make them cover fixed sized width. may be by adjusting the width of whole string? any idea?

                D 1 Reply Last reply
                0
                • K kedarrkulkarni

                  yes dave. but can i use proportial spaced font and still make them cover fixed sized width. may be by adjusting the width of whole string? any idea?

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #9

                  kedarrkulkarni wrote:

                  can i use proportial spaced font and still make them cover fixed sized width.

                  Not easily. You'd have to draw the text, line-by-line and word-by-word, yourself, adjusting the space between words to make the text justified between the margins.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007, 2008

                  K 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    kedarrkulkarni wrote:

                    can i use proportial spaced font and still make them cover fixed sized width.

                    Not easily. You'd have to draw the text, line-by-line and word-by-word, yourself, adjusting the space between words to make the text justified between the margins.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007, 2008

                    K Offline
                    K Offline
                    kedarrkulkarni
                    wrote on last edited by
                    #10

                    how can i mention the width of space betwwen the two characters while drawstring() Any idea? Thanx for reply... Cheers !

                    D 1 Reply Last reply
                    0
                    • K kedarrkulkarni

                      how can i mention the width of space betwwen the two characters while drawstring() Any idea? Thanx for reply... Cheers !

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #11

                      You can't. You can set the spacing between all characters in the string, but not between any two arbitrary characters. Like I said, if you want to do margin justified text, you'll have to drwa each individual word, keeping track of the position of each word and calculating the space needed between them.

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                           2006, 2007, 2008

                      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