I'm trying to use PdfContentByte and ColumnText to display notes imported from customer orders. The document and notes display correctly however, when I scroll down at all in the document, I get an error saying "An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem" I've looked around and found answers like: PDFs generated using itextsharp giving error at the time of first print command But the method doesn't appear to have any nesting issues:
private void DisplayNotes(OrderVerificationData ovNotes)
{
_notes = ovNotes.orderNotes;
_resultNotes = _notes.Split(_notesSeparators, StringSplitOptions.RemoveEmptyEntries);
Phrase notesDisplay = FormatPhrase("");
PdfContentByte dc = _instance.DirectContent;
var ct = new ColumnText(dc);
foreach (string t in _resultNotes)
{
notesDisplay.Add(t);
notesDisplay.Add(Environment.NewLine);
}
dc.BeginText();
dc.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 10f);
dc.SetTextMatrix(50f, _verticalAlign);
if (_verticalAlign <= 40)//new page stuff, error still occurs when commented out
{
dc.EndText();
FooterCreation(ovNotes);
_document.NewPage();
_numberOfPages += 1;
_verticalAlign = 690;
dc.BeginText();
dc.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false), 9f);
dc.SetTextMatrix(50f, _verticalAlign);
}
ct.SetSimpleColumn(notesDisplay, 55f, 0f, 400f, _verticalAlign, 10f, Element.ALIGN_LEFT);
ct.Go();
dc.EndText();
}
I don't recall column text needing to be closed, nor could I find anything that said it had to be. Is there something else that's causing this issue? Removing all usage of this method from the rest of the file causes the pdf to be displayed properly.