I created a printDocument object that prints out a report. It works fine. This is the OnPrintPage event handler:
private void OnPrintPage(object sender, PrintPageEventArgs e)
{
if (page == 2)
{
Header(e);
Page2(e);
}
else
{
Header(e);
Page1(e);
}
}
I want to create a PDF of the same document. This is the code:
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Create PDF";
sfd.Filter = "(*.pdf)|*.pdf";
if (sfd.ShowDialog() == DialogResult.OK)
{
iTextSharp.text.Document doc = new iTextSharp.text.Document();
PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create));
doc.Open();
doc.Add(new iTextSharp.text.Paragraph(printDocument));
doc.Close();
}
This doesn't work. Can you please help me to identify the problem and find a solution? Thank you.