- Code: Select all
// print document #1
using (var doc1 = new PdfDocument())
{
var page1 = doc1.Pages.Add();
using (var font1 = new PdfTrueTypeFont(new Font("arial", 12.0f), false))
{
var brush1 = new PdfSolidBrush(Color.Black);
var point1 = new PointF(1, 1);
// print document #2
using (var doc2 = new PdfDocument())
{
var page2 = doc2.Pages.Add();
using (var font2 = new PdfTrueTypeFont(new Font("arial", 12.0f), false))
{
var brush2 = new PdfSolidBrush(Color.Black);
var point2 = new PointF(1, 1);
page2.Canvas.DrawString("Hello world from doc 2", font2, brush2, point2);
doc2.SaveToFile(@"C:\test\doc2.pdf");
}
}
// **** here it will crash with null ref exception ****
page1.Canvas.DrawString("Hello world from doc 1", font1, brush1, point1);
doc1.SaveToFile(@"C:\test\doc1.pdf");
}
}
Please let me know if a fix is available.
Thank you