使用 C# 编辑 pdf 书签 url
我有一个 pdf 文件,其中包含不同章节的书签(每个章节都使用书签链接到单独文件夹中的另一个 pdf 文件)。单击每个章节名称将在同一父 pdf 文件中打开一个新 pdf。
我需要检索父 pdf 文件的书签 url 并更改 URL。我使用下面的代码来检索书签属性(操作、文件、标题等),但是没有成功更改路径,因为它是字典键值对。
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
}
}
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
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过两步完成此操作。
IList
并进行任何所需的更改。PdfReader
再次打开父 PDF。然后用您在步骤 1 中更新的内容覆盖现有书签:请注意,在第 1 步中,您必须考虑一些
bmProperty
(上面代码中的IDictionary
)如果您的书签具有嵌套级别,值本身可能是Dictionary
对象。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:Note that in step 1 you must take into account that some of the
bmProperty
(IDictionary
from your code above) values may themselves beDictionary<String, Object>
objects, if your bookmarks have nested levels.我对 itextsharp 对您的要求没有太多信心..但是还有另一个库 PDFSharp 具有一些很好的书签功能...
文本中的 PDFsharp 书签
http://www.pdfsharp.net/wiki/Bookmarks-sample.ashx
问候。
i don't have much confidence about itextsharp about your requirement.. but there is another library PDFSharp that has some good bookmark functionality...
PDFsharp bookmarks in text
http://www.pdfsharp.net/wiki/Bookmarks-sample.ashx
Regards.