I need to put a print page inside my code, ie I will not print an existing document, nor the application screen, I want to mount the code with the elements I want.
I have an array and I just want to add text that is in it to my document.
I'm a layman and started like this (I do not know if it's the right approach):
public void Imprimir(Array dados)
{
var documento = new System.Drawing.Printing.PrintDocument();
foreach(var dado in dados)
{
// aqui popularia o documento com os textos pra no final so chamar o .Print()
// não sei como fazer isso
}
documento.Print();
}
At first I just want to make print something to increase the solution and set paper size, insert images and etc ...
I tested it this way and printed the blank page:
public void Imprimir(Array dados)
{
var documento = new System.Drawing.Printing.PrintDocument();
foreach(var dado in dados)
{
documento.PrintPage += meuDocumento;
}
documento.Print();
}
private void meuDocumento(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.PageUnit = GraphicsUnit.Inch;
e.Graphics.DrawString("Linha 1", new Font("arial", 10), Brushes.Black, 100, 2);
e.Graphics.DrawString("Linha 2", new Font("arial", 10), Brushes.Black, 200, 2);
}