Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The paper size is 15 cms. Print area size is 10 cm. How can I center the title and fill the columns with data fitting in that 10 cms?. It is a continuous paper with perforations. Thank You

addtional information copied from non-solution below
Thanks. I have Calculated the height of header and footer and how much space I can get in between. I have put all contents in an array and started printing it in picturebox. Now there is one problem. The printer's page height (height of the paper which comes out of printer) stays constant even after I set the printer.height value. The paper stops at 11 inches despite me changing the paper size / adding new paper size etc. How can I stop printing at exactly at my page height?? Thank You For Your Time
Posted
Updated 29-Nov-13 0:13am
v2
Comments
CHill60 27-Nov-13 17:31pm    
You could calculate the width each character will use up depending on the size font you have used. That will give you the number of characters you could print across the page, then start printing your text at (maxchars - textlength) / 2 or pad it with that many spaces at the front. Same principle with the columns. Don't think you have many options other than "brute force" with dot-matrix printers
Tegimus 28-Nov-13 1:06am    
Okay I have done It the way you suggested. Now the problem is content length. I need to print the contents between header and footer. If it doesn't fit, put it in the next page between header and footer. How can I acheive this? Thank You
CHill60 28-Nov-13 8:10am    
I've added this as a solution - it's easier to read! :-)
CHill60 30-Nov-13 8:09am    
I'm confused - why are you using a picturebox? Do you get this same behaviour if you just print a line number followed by a crlf? Last time I went through an exercise like this I ignored any "settings" and just output to the printer port - keeping control of what was going on myself.

For the intial problem I suggested ...
You could calculate the width each character will use up depending on the size font you have used. That will give you the number of characters you could print across the page, then start printing your text at (maxchars - textlength) / 2 or pad it with that many spaces at the front. Same principle with the columns. Don't think you have many options other than "brute force" with dot-matrix printers.

From the OPs comment that seems to have worked, but we now have a new issue ...
Tegimus:
Okay I have done It the way you suggested. Now the problem is content length. I need to print the contents between header and footer. If it doesn't fit, put it in the next page between header and footer. How can I acheive this? Thank You
So ...

Same principle really ... just work out how much physical space your header and footer are going to take - subtract that from the overall length available. Work out how many lines of print you can get into that space given the font size you are using - remember to round down though.

Keep a line count of what you are printing, when you reach the limit print your footer, pagethrow, header and then start with the next line of detail.

Hint: This isn't the best way to do output, but in circumstances like a dot-matrix printer you often have no choice. Similar (width) problems exist for continuous printers for till receipts etc. Essentially this is a fixed-format print. I would still advise trying to parameterise the information as much as possible - i.e. a calculation on max line count based on physical paper size stored in configuration somewhere.
 
Share this answer
 
Comments
Nelek 29-Nov-13 6:13am    
Have a look, OP posted non-solution to speak with you. I have updated the question with that content.
CHill60 30-Nov-13 8:05am    
Thanks Nelek. I'll have another look
Thanks. I have Calculated the height of header and footer and how much space I can get in between. I have put all contents in an array and started printing it in picturebox. Now there is one problem. The printer's page height (height of the paper which comes out of printer) stays constant even after I set the printer.height value. The paper stops at 11 inches despite me changing the paper size / adding new paper size etc. How can I stop printing at exactly at my page height?? Thank You For Your Time
 
Share this answer
 
Comments
Nelek 29-Nov-13 6:12am    
Please don't post solutions to chat with people asking or answering. The messages are not always sorted by date, so it can be a bit difficult to follow them correctly.
The best option is to use the "Have a question or comment?" (or the tiny "reply" on another comment). Another advantage is, that the person you write to will get a notification, otherwise it could be that he/she doesn't see your additional question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900