winforms - print preprinted invoice, field in position x,y c# from a file format -
excuse me, english
well, see in program when need print first thing read file contain line , column of fields print in matrix printer (a printer of points, don't find correct word)
my idea write in file position of fields need print this
(x,y) fields1, (x,y) fields2, (x,y) fields3,
and way print every fields, program need read file print, way allow me change position of fields in format if preprinted document need print change something
i wanna because have many diferent preprinted invoice , need adjust printer way
i read printdocument don't found explanation of , read this, simple example
i hope can guide me in right direction
i don't think type of printer matters (matrix vs. inkjet vs. laser). here more complete code example.
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.printpage.aspx
for specific scenario, need parse x,y position information out of invoice format file each field. once have x , y, draw printpage event arguments graphics
object in example code.
the tricky part parsing format file correct x , y position data. can make things easier using simple format. example, format file follows.
x y [field1] x y [field2] ...
so let's want print simple page looks this.
07-31-2013 invoice page 1 item quantity price -------- -------- -------- sprocket 1 $100.00 cog 2 $ 25.00 total: $150.00
your actual formatted invoice file be...
1 1 07-31-2013 1 20 invoice 1 40 page 1 3 1 item 3 20 quantity 3 40 price 4 1 -------- 4 20 -------- 4 40 -------- 5 1 sprocket 5 20 1 5 40 $100.00 6 1 cog 6 20 2 6 40 $ 25.00 8 1 total: $150.00
and code print this.
// printpage event raised each page printed. private void pd_printpage(object sender, printpageeventargs ev) { int row = 0; int col = 0; float xpos = 0; float ypos = 0; float leftmargin = ev.marginbounds.left; float topmargin = ev.marginbounds.top; string line = null; // print each line of file. while (true) { try { row = convert.toint32(streamtoprint.readline()); col = convert.toint32(streamtoprint.readline()); line = streamtoprint.readline(); } catch { break; } xpos = leftmargin + (col * ev.graphics.measurestring(" ", printfont, ev.pagebounds.width)); ypos = topmargin + (row * printfont.getheight(ev.graphics)); ev.graphics.drawstring(line, printfont, brushes.black, xpos, ypos, new stringformat()); } }
Comments
Post a Comment