我在使用iTextSharp库将XMP元数据写入c#中的现有pdf文件时遇到问题。这是我的,但它不起作用。任何建议
string src = @"C:\test\Test Artifact Document.pdf";
PdfReader reader = new PdfReader(src);
using (MemoryStream ms = new MemoryStream())
{
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
Dictionary<String, String> info = reader.Info;
using (MemoryStream msXmp = new MemoryStream())
{
XmpWriter xmp = new XmpWriter(msXmp, info);
xmp.SetProperty(XmpConstants.NsDC, "Firm", "FBI");
xmp.Close();
stamper.XmpMetadata = msXmp.ToArray();
}
}
}
提前致谢!
答案 0 :(得分:1)
我认为问题在于代码未保存更改。 压模将更改写入MemoryStream中,如果您不将更改保存到文件中,则不是在保存它们。
string src = @"C:\test\Test Artifact Document.pdf";
PdfReader reader = new PdfReader(src);
using (MemoryStream ms = new MemoryStream())
{
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
Dictionary<String, String> info = reader.Info;
using (MemoryStream msXmp = new MemoryStream())
{
XmpWriter xmp = new XmpWriter(msXmp, info);
xmp.SetProperty(XmpConstants.NsDC, "Firm", "FBI");
xmp.Close();
stamper.XmpMetadata = msXmp.ToArray();
}
stamper.Close();
}
File.WriteAllBytes(@"C:\test\Test Artifact Document (1).pdf", ms.ToArray());
}
免责声明:这是我的第一时间在这里回答……等等……不要太苛刻。我只是在回答这个问题,因为Google几次把我带到这里,而我再也看不到它没有答案了。
答案 1 :(得分:0)