Hi, can anyone help with this? I am adding an anchor to a canvas. The
canvas is the 'over content' for a single page in a PDFStamper object. The
anchor is an internal reference to a name on another page.
When I use ColumnText.ShowTextAligned to add the anchor I am getting a
'Object reference not set to an instance of an object' error. Is it because
the canvas does not contain the target reference? If so, what can I do?
Here is a working example of the problem:
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
var ms = new MemoryStream();
var document = new iTextSharp.text.Document();
// Create a simple two page PDF document:
var pdfWriter = PdfWriter.GetInstance(document, ms);
pdfWriter.InitialLeading = 40F;
document.Open();
document.Add(new Phrase("Simple Phrase on Page 1"));
document.NewPage();
document.Add(new Phrase("Simple Phrase on Page 2"));
document.Close();
// Read the 2 page document, create a stamper and add two anchors
// at absolute positions on page 1.
var pdfReader = new PdfReader(ms.ToArray());
var ms2 = new MemoryStream();
var pdfStamper = new PdfStamper(pdfReader, ms2);
var canvas = pdfStamper.GetOverContent(1);
// add an external anchor
var anchor1 = new Anchor("External Anchor");
anchor1.Reference = "www.stackoverflow.com";
ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, anchor1, 100,
200, 0);
// add an internal anchor
var anchor2 = new Anchor("Internal Anchor");
anchor2.Reference = "#abc";
// this next line causes a null reference exception - why?
ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, anchor2, 100,
100, 0);
pdfStamper.Close();
Thanks, Paul.
------------------------------------------------------------------------------
Own the Future-Intel® Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game
on Steam. $5K grand prize plus 10 genre and skill prizes.
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php