graphics.drawstring and placement

ideprize

Well-known member
Joined
Oct 19, 2011
Messages
97
Programming Experience
10+
After many hours of debugging it has become abundantly clear that graphics.drawstring does not replicate text placement from an input text file. It varies the placement of the text on the target document by some algorithm I have yet to define. In particular what I am experiencing is addresses on the right side of a post card - good luck on that alignment even though the text coming in from a ascii file is perfect! What I am trying to do is print "reminder cards" 3 to a page and the placement of the text is critical. Is there any other methodology available to send text to a printer other than graphics.drawstring because this dog don't hunt!

Respectfully,
Gordon Haas
 
There is no text placement in a text file to replicate. A text file contains text only - no font or formatting information. If you want to print then using Graphics.DrawString in a PrintPage event handler is how you do it. Positioning text is not too difficult but it's also not completely trivial. You're obviously doing it wrong but we don't know what you're doing so we can't know what's wrong with it. Tell us what you want to do, how you're trying to do it and how the result differs from expectations and we may be able to help you fix your errors.
 
First and foremost let me say thanks for the reply.
I thought this was going to be a simple case of in and out. I am using the readline method scripting.textstream object. I read each line into a "string buffer" a line at a time until I acquire a page. I place a chr(13) and chr(10) at the end of each line in the string buffer as I build it. When I acquire a page I transfer the page to the printer via the printpage event (I have the printdocument object in my form via VS 2005). The vertical space is perfect and so is 95% of the horizontal space/placement is replicated. However, the white space is causing problems, i.e.



in:
Pet age 10 Yr 4 Mo Pet #18658 Client #26 Donald Simmons
2533 Toddville Rd.


Out:
Pet age 10 Yr 4 Mo Pet #18658 Client #26 Donald Simmons
2533 Toddville Rd.


Whenever there is a "large" blanked area in the line the graphics.drawstring method squeezes the spaces. In the example above going in Donald starts at character position 60 and so does the 2 of 2533. And I have verified this with debug. They are also occupying this space relationship in the "string buffer". What graphics.drawstring is doing I am not certain of but I think it has something to do with a "graphics legacy". It is telling me in no uncertain terms it does not like continuous spaces. If I pad the line, however, with 24 spaces it realigns. Ultimately, I have to think the "font" has something to do with this but why doesn't the font impact ALL lines. The incoming file does have a 16.6 CPI - pitch. The way I have "worked around the problem is through padding with blanks. This data is being placed on reminder cards 3 to a page. The data that is being impacted is, of course, the address. If you are wondering why am I doing this in the first place that has to do with the new philosophy of the business printers vendors which states - no ink shall be allowed to be placed in the last half inch of the page! Thus I need to add intelligence to keep registration in sync between pages!! I of course have been looking at the hex profile of the input file as well and it is perfect with regards to character count. The input file is a "pure ascii" file. Thanks in advance.

Respectfully,
Gordon Haas
 
This is a continuation to the last thread. I did not realize that the submission would invalidate my in and out example. The in segment should have the "2533" address directly under Donald Simmons and the out segment should have the "2533" address skewed to the left by approximately 24 positions.

Gordon Haas
 
What font are you using to print? I'm guessing that you're using a variable-width font, in which case space characters are likely to be significantly narrower than other characters. If you open a file in Notepad then it will use a fixed-width font by default. Change the font in Notepad and you'll see something similar to what's getting printed.

If you want to use a variable-width font, which you most likely do because fixed-width fonts are generally ugly, then you'll have to break the text into blocks and then position each block of text appropriate with individual calls to DrawString for each block.
 
That makes sense and that is what I saw - the space was changing. And no I do not want a variable-width font. I want replication of the input file so how do I get a static font? Again Thanks for your help.

Gordon Haas
 
As a continuation of the above thread could you please tell me whether or not I am communicating a monospace font.


Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim font1 As New Font("Courier", 8)e.Graphics.DrawString(strPrtfl, font1, Brushes.Black, 0, 0)

Changing e.Graphics.Drawstring(StrPrtfl, me.font, Brushes.Black, 0, 0) to the above setup does not remove the varying width outcome? Am I missing something? No, rather what am I missing?

Gordon Haas
 
Problem has been solved. I found a write-up on the web posted by an individual that was referencing exactly what I was experiencing. His interface identified the System.Drawing.FontFamily.GenericMonospace font to be used for the monospace font - this setup replicates the input file exactly and when you are sending reminder post cards "exactly" is what you need! Now if I could only get the business printer manufacturers to remove the concrete mask from the last half inch of the printed page I would have the ability to increase the content on the post cards!

Thanks for your help gmcilhinney you identified the element that needed to be changed.

Respectfully,
Gordon Haas
 
Just keep in mind that it is NOT the case that your printing was wrong or that it was not accurately representing the file contents. As I said the file contains no font or formatting information. You said that you wanted replication of the input file but you already had that. What you actually wanted was replication of the way NotePad, our maybe some other text editor, displayed the file by default. That same text editor could just as easily display the file as you were printing it if you simply changed the display font.
 
I understand and appreciate your abstractions. Sufficeth to say the space we are now entering is semantics. In this case my usage of replication implied the physical construct of the data as well as the content or perhaps to be more definitive what I wanted was an isomorphic relationship between the input and output because of the mission. Again thanks for your insight. You definitely understood what was going on more so than I.

Respectfully,
Gordon Haas
 
Back
Top