Print Labels C#

  • Thread starter Thread starter ooooscar
  • Start date Start date
O

ooooscar

I'd like to make an application to print labels. I have to print an image
and text, the label size is 10cm x 5 cm. I'm wandering how to do it in c#.
My first thought is to make an acrobat "form" with the image and text, but I
have to send a date in the label so I need to open the pdf and send the date
into a field (variable), then I have to print n times the same label.

Can anyone help me ?

Thank's.
 
I'd just write the drawing code to draw the label and then offset it n
times for each label on a row and the add the row spacing to the start and
repeat until the page is filled. Put all this into a PrintDocument subclass
and make sure to account for the printer 'hard' margins and everything
should work easily. If you need to get very precise alignment setup your
calling program to provide x/y offsets and then store them in application
settings. Just put the varying fields on the form into an ArrayList and
loop through it until all are printed.

Ron Allen
 
I don't understand your comment.
Sorry.
Ron Allen said:
I'd just write the drawing code to draw the label and then offset it n
times for each label on a row and the add the row spacing to the start and
repeat until the page is filled. Put all this into a PrintDocument subclass
and make sure to account for the printer 'hard' margins and everything
should work easily. If you need to get very precise alignment setup your
calling program to provide x/y offsets and then store them in application
settings. Just put the varying fields on the form into an ArrayList and
loop through it until all are printed.

Ron Allen
 
I'm normally used to doing all my own drawing in print jobs so thats how
I explained it. I'd write a custom PrintDocument class and then pass in an
ArrayList (or something) with all the label data. A brief outline of the
code for the OnPrintPage would be
protected override void OnPrintPage(PrintPageEventArgs e)
{
base.OnPrintPage(e);
float cury = 1.0f; // or whatever is needed (everything in
inches)
float bottom = 10.0f; // bottom of labels
float labelht = 1.0f; // height of a label top of one to the next
float leftx = 1.0f; // leftmost label position
float curx = leftx; // current x position
float rightx = 7.5f; // rightmost position
float colwidth = 2.0f;
// nLabel is a integer declared as a class variable -- index into the
ArrayList
while ((nLabel < labelCount) && (cury < bottom))
{
DrawLabel(e, nLabel, cury, curx, Labels[nLabel]);
curx += colwidth;
if (curx > rightx)
{
cury += labelht;
curx = leftx;
}
}
if (nLabel < labelCount) // more labels to print
e.HasMorePages = true;
else
e.HasMorePages = false; // done printing
}
DrawLabel would just take the Graphics from the supplied PrintPageEventArgs,
the x/y position and the data in the Labels list (a group of strings or
whatever) and draw it on the page as desired. Labels spread across the page
from left to right and then top to bottom. You could pass in the variables
for top of page, right of page, column width, and label height to the
subclass to make this more general. DrawLabel would just be something that
printed each supplied string seperated by a specified height on the label.

Ron Allen
 
Back
Top