Env
- Windows 10 .NET 4.7
- Aspose.PDF for NET 22.12
Q1
Aspose get a wrong result when set a new metadata value for KeyWords
, steps:
- PDF has a metadata
KeyWords
, its value is DDD
- Change new value for
KeyWords
to 444
- It get a wrong result, it became
444; DDD
, the except result should be 444
Q2
Aspose overwrites original Creator
and Producer
content, and I didn’t actually change them.
Creator
became to Aspose Pty Ltd.
and Producer
became to Aspose.PDF for.NET 22.12.0
.
Code
var doc = new Aspose.Pdf.Document(@"C:\Users\XCL\Desktop\test\source.pdf");
doc.Info.Title = "111";
doc.Info.Author = "222";
doc.Info.Subject = "333";
doc.Info.Keywords = "444";
doc.Save(@"C:\Users\XCL\Desktop\test\target.pdf");
Before
image.png (45.8 KB)
After
image.png (45.0 KB)
Test Files
test.zip (112.1 KB)
@xucongli1989
We have logged this problem in our issue tracking system as PDFNET-53367. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.
PdfFileInfo class allows you to set file specific information of a PDF file. Please read the following article for more detail:
Set PDF File Information
@xucongli1989
This behavior is not a bug, Adobe Acrobat reads keywords not only from the DocumentInfo.Keywords, but from XMP Metadata properties as well (namely, “pdf:keywords” and “dc:subject” properties). To fully replace keywords in the document you may use PdfFileInfo
and PdfXmpMetadata
, for example as shown here:
using (var docInfo = new PdfFileInfo(@"source.pdf"))
{
docInfo.Title = "111";
docInfo.Author = "222";
docInfo.Subject = "333";
docInfo.Keywords = "444";
// Save new DocumentInfo AND update XMP metadata with the same values
docInfo.SaveNewInfoWithXmp(@"target.pdf");
}
// Update additional metadata key that Adobe Reader uses as a keywords source
using (var xmp = new PdfXmpMetadata())
{
xmp.BindPdf(@"target.pdf");
xmp["dc:subject"] = keywords;
xmp.Save(outputPath);
}