Yes, i tried this, still not working. Actually this is what I'm trying to achieve: I need to add an anchor to an existing pdf in order to return the user to the top of the page when clicked
public void Bookmark() {
PdfReader reader = new PdfReader(new RandomAccessFileOrArray(_fileName), null);
DeleteFile(); //delete old pdf (_filename)
_fileName = Setting.Temp + Guid.NewGuid() + ".pdf";
Document doc = new Document(PageSize.A4, 0, 0, 50, 50);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(_fileName, FileMode.Create));
iTextSharp.text.Font link = FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.UNDERLINE, BaseColor.BLUE);
doc.Open();
PdfContentByte pdfContentByte = writer.DirectContent;
Anchor topAnchor = null;
PdfImportedPage page = null;
for (int i = 1; i < reader.NumberOfPages; i++) {
if (i == 1) {
topAnchor = new Anchor();
topAnchor.Name = "TopAnchor";
page = writer.GetImportedPage(reader, i);
doc.NewPage();
pdfContentByte.AddTemplate(page, 0, 0);
doc.Add(topAnchor);
} else {
page = writer.GetImportedPage(reader, i);
doc.NewPage();
pdfContentByte.AddTemplate(page, 0, 0);
Anchor anchor = new Anchor("Back to Top", link);
anchor.Reference = "#TopAnchor";
doc.Add(anchor);
}
}
doc.Close();
}
capiono
Member
22 Points
59 Posts
How add anchor to existing PDf using Itextsharp?
Dec 18, 2012 04:56 PM|LINK
Can someone please tell me how to add anchor to an existing pdf? i have search the web, but all I found was adding anchors to new pdf.
Thanks for you help.
urenjoy
Star
12027 Points
1807 Posts
Re: How add anchor to existing PDf using Itextsharp?
Dec 19, 2012 10:18 AM|LINK
Have a look at following:
http://www.mikesdotnetting.com/Article/84/iTextSharp-Links-and-Bookmarks
capiono
Member
22 Points
59 Posts
Re: How add anchor to existing PDf using Itextsharp?
Dec 19, 2012 11:35 AM|LINK
Yes, i tried this, still not working. Actually this is what I'm trying to achieve: I need to add an anchor to an existing pdf in order to return the user to the top of the page when clicked
public void Bookmark() { PdfReader reader = new PdfReader(new RandomAccessFileOrArray(_fileName), null); DeleteFile(); //delete old pdf (_filename) _fileName = Setting.Temp + Guid.NewGuid() + ".pdf"; Document doc = new Document(PageSize.A4, 0, 0, 50, 50); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(_fileName, FileMode.Create)); iTextSharp.text.Font link = FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.UNDERLINE, BaseColor.BLUE); doc.Open(); PdfContentByte pdfContentByte = writer.DirectContent; Anchor topAnchor = null; PdfImportedPage page = null; for (int i = 1; i < reader.NumberOfPages; i++) { if (i == 1) { topAnchor = new Anchor(); topAnchor.Name = "TopAnchor"; page = writer.GetImportedPage(reader, i); doc.NewPage(); pdfContentByte.AddTemplate(page, 0, 0); doc.Add(topAnchor); } else { page = writer.GetImportedPage(reader, i); doc.NewPage(); pdfContentByte.AddTemplate(page, 0, 0); Anchor anchor = new Anchor("Back to Top", link); anchor.Reference = "#TopAnchor"; doc.Add(anchor); } } doc.Close(); }april_123456
Participant
775 Points
246 Posts
Re: How add anchor to existing PDf using Itextsharp?
Dec 21, 2012 03:54 AM|LINK
Hello capiono!
To create page jumps, please refer to the following link - you may find it useful.
http://en.support.wordpress.com/splitting-content/page-jumps/
Best of Luck!
With Kind Regards,