2
我在我的C#項目中使用iTextSharp庫來讀取和編輯pdf文檔。 現在我想更改某個pdf文檔的標題。 我搜索了很多關於這個問題,但沒有真正適用於我。 最好的我發現的是以下幾點:C#:iTextSharp,我如何編輯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();
}
但Visual Studio中說,System.Collection.Hashtable
不能轉換成隱System.Collections.Generic.IDictionary<string,string>
。已經有一個現有的轉換。
希望任何人都可以幫助我。或者有iTextSharp編輯標題的另一個解決方案。