Reputation: 21
I have a pdf file which has bookmarks to different chapters(each chapter is linked to another pdf file in seperate folder using bookmarks). clicking on each chaptername will open a new pdf in the same parent pdf file.
I need to retrieve the bookmark urls of parent pdf file and alter the URLs.I used below code to retrieve bookmark properties(Action,File,Title etc), however didn't succeed in altering the path as it is dictionary key value pair.
IList<Dictionary<String, Object>> bmProperties= SimpleBookmark.GetBookmark(new PdfReader(new RandomAccessFileOrArray("http://XXXX/Shared%20Documents/Chapters.pdf"),
null));
foreach (IDictionary<String, Object> bmProperty in bmProperties)
{
foreach (var fileProperty in bmProperty.Keys)
{
if (fileProperty == "File")
{
// need the edit the value of Key-"File". Will it be possible to alter the value using pdfwriter
}
}
Upvotes: 0
Views: 2556
Reputation: 9372
You can accomplish this in two steps.
IList
and make any needed changes.PdfReader
. Then overwrite the existing bookmarks with what you updated in step 1:PdfReader reader = new PdfReader(PARENT-PDF-FILE); using (PdfStamper stamper = new PdfStamper(reader, YOUR-STREAM)) { stamper.Outlines = bmProperties; }
Note that in step 1 you must take into account that some of the bmProperty
(IDictionary
from your code above) values may themselves be Dictionary<String, Object>
objects, if your bookmarks have nested levels.
Upvotes: 1
Reputation: 4585
i don't have much confidence about itextsharp about your requirement.. but there is another library PDFSharp that has some good bookmark functionality...
http://www.pdfsharp.net/wiki/Bookmarks-sample.ashx
Regards.
Upvotes: 0