Hello,
I am using ITextPdf 7.1.13 Library to create a report for a project using C# ASP NET.
The problem is that the pdf generated it's fine on my pc.
However, when I save my project it as website on the remote server generate this error.
CS1061: 'iText.Kernel.Pdf.Canvas.PdfCanvas' does not contain a definition of' AddXObjectAt 'and no' AddXObjectAt 'extension method was found that accepts a first argument of type' iText.Kernel.Pdf.Canvas.PdfCanvas '. Probably missing a using directive or assembly reference.
If comment this line the pdf it's generated fine but without total of pages on pdf file.
pdfCanvas.AddXObjectAt(placeholder, x + space, y - descent);
code-behind
private class TableFooterEventHandler : IEventHandler
{
private Table table;
public TableFooterEventHandler(Table table)
{
this.table = table;
}
public void HandleEvent(Event currentEvent)
{
PdfDocumentEvent docEvent = (PdfDocumentEvent)currentEvent;
PdfDocument pdfDoc = docEvent.GetDocument();
PdfPage page = docEvent.GetPage();
int pageNumber = pdfDoc.GetPageNumber(page);
Rectangle pageSize = page.GetPageSize();
PdfCanvas canvas = new PdfCanvas(page.NewContentStreamBefore(), page.GetResources(), pdfDoc);
new Canvas(canvas, new Rectangle(36, 20, page.GetPageSize().GetWidth() - 72, 50))
.Add(table)
.Close();
}
}
protected class Footer : IEventHandler
{
protected PdfFormXObject placeholder;
protected float side = 20;
protected float x = 300;
protected float y = 25;
protected float space = 4.5f;
protected float descent = 3;
public Footer()
{
placeholder = new PdfFormXObject(new Rectangle(0, 0, side, side));
}
public virtual void HandleEvent(Event @event)
{
PdfDocumentEvent docEvent = (PdfDocumentEvent)@event;
PdfDocument pdf = docEvent.GetDocument();
PdfPage page = docEvent.GetPage();
int pageNumber = pdf.GetPageNumber(page);
Rectangle pageSize = page.GetPageSize();
// Creates drawing canvas
PdfCanvas pdfCanvas = new PdfCanvas(page);
Canvas canvas = new Canvas(pdfCanvas, pageSize);
canvas.SetFontSize(10);
Paragraph p = new Paragraph()
.Add("Page ")
.Add(pageNumber.ToString())
.Add(" of");
canvas.ShowTextAligned(p, x, y, TextAlignment.RIGHT);
canvas.Close();
// Create placeholder object to write number of pages
pdfCanvas.AddXObjectAt(placeholder, x + space, y - descent);
pdfCanvas.Release();
}
public void WriteTotal(PdfDocument pdfDoc)
{
Canvas canvas = new Canvas(placeholder, pdfDoc);
canvas.SetFontSize(10);
canvas.ShowTextAligned(pdfDoc.GetNumberOfPages().ToString(),
0, descent, TextAlignment.LEFT);
canvas.Close();
}
}