PdfSharp
参照ライブラリを使用して、メタデータタグを追加する機能をプログラムに追加しようとしています。ドキュメントにメタデータタグを追加することはできますが、既存のカスタムプロパティのタグを更新する際に問題があります。私のメソッドを使用してカスタムプロパティを更新しようとすると、次の例外が発生します。PdfSharp、C#でのメタデータの更新
"'System.Collections.Generic.KeyValuePair'に 'Name'の定義が含まれていません。
foreachループでif文をコーディングすると、PDFドキュメント内のカスタム要素をすべて正しくループして、存在し、更新する必要があるかどうか教えてもらえますか?ありがとう。
public void AddMetaDataPDF(string property, string propertyValue, string
path)
{
PdfDocument document = PdfReader.Open(path);
bool propertyFound = false;
try {
dynamic properties = document.Info.Elements;
foreach(dynamic p in properties)
{
//Check to see if the property exists. If it does, update
value.
if(string.Equals(p.Name, property,
StringComparison.InvariantCultureIgnoreCase))
{
document.Info.Elements.SetValue("/" + property, new
PdfString(propertyValue));
}
}
// the property doesn't exist so add it
if(!propertyFound)
{
document.Info.Elements.Add(new KeyValuePair<String, PdfItem>
("/"+ property, new PdfString(propertyValue)));
}
}
catch (Exception ex)
{
MessageBox.Show(path + "\n" + ex.Message);
document.Close();
}
finally
{
if(document != null)
{
document.Save(path);
document.Close();
}
}
}
ありがとうございます。それはうまくいった。皆さんはこのフォーラムですごく役立ちます。 – Dwayne