I'm getting this error where is says
gfx = XGraphics.FromPdfPage(page);
can someone explain how I need to fix this?
Cannot create XGraphics for a page of a document that cannot be modified. Use PdfDocumentOpenMode.Modify.
Code:
if (checkBox1.Checked == true)
{
MessageBox.Show("Printing Page Numbers.");
PdfDocument outputDocument = new PdfDocument();
XFont font = new XFont("Verdana", 10, XFontStyle.Bold);
XStringFormat format = new XStringFormat();
format.Alignment = XStringAlignment.Center;
format.LineAlignment = XLineAlignment.Far;
XGraphics gfx;
XRect box;
foreach (string file in pdfList.Items)
{
PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import);
int count = inputDocument.PageCount;
for (int idx = 0; idx < count; idx++)
{
PdfPage page = inputDocument.PageCount > idx ?
inputDocument.Pages[idx] : new PdfPage();
gfx = XGraphics.FromPdfPage(page);
box = page.MediaBox.ToXRect();
box.Inflate(0, -10);
gfx.DrawString(String.Format("{0} • {1}", file, idx + 1),
font, XBrushes.Red, box, format);
outputDocument.AddPage(page);
}
}