I'm quite new to c# and need some help with formating a document for printing.
I already managed to talk to the printer via this code:
private void Print(string printer)
{
PrintDocument PrintDoc = new PrintDocument();
PrintDoc.PrinterSettings.PrinterName = printer;
PrintDoc.PrintPage += new PrintPageEventHandler(PrintPage);
PrintDoc.Print();
}
void PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawLine(new Pen(Color.Black), new Point(0, 0), new Point(100, 100));
e.Graphics.DrawString("Hello World", new Font("Times New Roman", 12), new SolidBrush(Color.Black), new Point(45, 45));
}
Which prints me my "hello world" string. Obviously the PrintPage method is code I found on the net. Sadly I couldn't find a way to
a) set the format the size of the paper I print on (it is 138mm x 99mm landscape format)
b) tell the printer where to print my texts exactly.
The paper is a preprinted form and I have to write my text in the specific fields.
So I'm looking for a way to give my printer a formated document like:
<field1>
<x> 2cm </x>
<y> 1cm </y>
<text> textfield1 </text>
</field1>
<field2>
....
I couldn't find information on how to do that. So if anyone could tell me how to do this or has a link to a good tutorial, I'd be very thankfull