4
I need to assemble a printing page inside my code, that is I will not print an existing document, nor the application screen, I want to assemble the code execution with the elements I want.
I have an array and I just want to add texts that are in it to my document.
I am a layman in this and started like this (I don’t 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 print something to increase the solution and define paper size, insert images and etc...
I tested 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);
}
I can pass other parameters to this method Print_printpage??
– Joao Paulo
Print_printpage is a standard Printdocument action method... It’s not a good solution. But it tells you what your idea is, what you want to do ?
– Cezar
It is pq as I will assemble the print there I already have a list in the previous method I want to iterate inside the Print_printpage to generate the print document.
– Joao Paulo
Call the method within the
Print_PrintPage
, got it?– Cezar