Printing text file in vb.net - Formatting issue
-
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 = psAddHandler 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?
-
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 = psAddHandler 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?
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 ***************************
-
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 ***************************
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
-
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
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 ?
-
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 ?
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 !
-
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 !
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 -
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 !
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
-
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, 2008yes 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?
-
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?
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 -
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, 2008how can i mention the width of space betwwen the two characters while drawstring() Any idea? Thanx for reply... Cheers !
-
how can i mention the width of space betwwen the two characters while drawstring() Any idea? Thanx for reply... Cheers !
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