小编Fab*_*roh的帖子

C#:iTextSharp,如何编辑pdf文档的title属性?

我在C#项目中使用iTextSharp库来读取和编辑pdf文档.现在我想更改某个pdf文档的标题.我搜索了很多关于这个问题,但没有什么对我有用.我发现的最好的是:

PdfReader pdfReader = new PdfReader(filePath);

using (FileStream fileStream = new FileStream(newFilePath, 
                                              FileMode.Create,
                                              FileAccess.Write))
{
    string title = pdfReader.Info["Title"] as string;
    Trace.WriteLine("Existing title: " + title);

    PdfStamper pdfStamper = new PdfStamper(pdfReader, fileStream);

    // The info property returns a copy of the internal HashTable
    Hashtable newInfo = pdfReader.Info;

    newInfo["Title"] = "New title";

    pdfStamper.MoreInfo = newInfo;

    pdfReader.Close();
    pdfStamper.Close();
}
Run Code Online (Sandbox Code Playgroud)

但Visual Studio表示System.Collection.Hashtable无法将其隐式转换为System.Collections.Generic.IDictionary<string,string>.已有转换.

希望有人能帮助我.或者使用iTextSharp的另一个解决方案来编辑​​标题.

c# pdf itextsharp

2
推荐指数
1
解决办法
2236
查看次数

标签 统计

c# ×1

itextsharp ×1

pdf ×1