I'm trying to print from windform, it turns out that when I print the document, I get the blank sheet. This is the code with which I try to print:
private PrintDocument printDocument1 = new PrintDocument();
private string stringToPrint;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
LeerArchivo();
printDocument1.Print();
}
private void LeerArchivo()
{
string docName = "1.pdf";
string docPath = @"C:\Firmador\";
printDocument1.DocumentName = docName;
using (FileStream stream = new FileStream(docPath + docName, FileMode.Open, FileAccess.Read))
using (StreamReader reader = new StreamReader(stream))
{
stringToPrint = reader.ReadToEnd();
}
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
int charactersOnPage = 0;
int linesPerPage = 0;
e.Graphics.MeasureString(stringToPrint, this.Font,
e.MarginBounds.Size, StringFormat.GenericTypographic,
out charactersOnPage, out linesPerPage);
e.Graphics.DrawString(stringToPrint, this.Font, Brushes.Black,
e.MarginBounds, StringFormat.GenericTypographic);
stringToPrint = stringToPrint.Substring(charactersOnPage);
e.HasMorePages = (stringToPrint.Length > 0);
}
private void printButton_Click(object sender, EventArgs e)
{
LeerArchivo();
printDocument1.Print();
}
This is what stringToPrint contains:
I would like to know if there is a way to correct it or some other way to print the file? Regards