Open marcelotavares opened 6 years ago
It's solved using OnCatalogWrite as the example bellow. But I need to create a pull request #239.
`
const pdfWriter = hummus.createWriterToModify(filename);
const data = new Buffer(metadata, 'utf-8');
const parser = pdfWriter.getModifiedFileParser();
const objectsContext = pdfWriter.getObjectsContext();
const aDictionary = parser.queryDictionaryObject(parser.getTrailer(),'Root').toPDFDictionary().toJSObject();
if(aDictionary["Metadata"])
{
const objectId = aDictionary["Metadata"].toPDFIndirectObjectReference().getObjectID();
objectsContext.startModifiedIndirectObject(objectId);
}
else
{
const objectId = objectsContext.startNewIndirectObject();
pdfWriter.requireCatalogUpdate();
pdfWriter.getEvents().on('OnCatalogWrite',function(dictionaryContext){
dictionaryContext.catalogDictionaryContext.writeKey('Metadata');
dictionaryContext.catalogDictionaryContext.writeObjectReferenceValue(objectId);
});
}
const pdfStream = objectsContext.startUnfilteredPDFStream();
pdfStream.getWriteStream().write([...data]);
objectsContext.endPDFStream(pdfStream);
objectsContext.endIndirectObject();
pdfWriter.end();
`
Hi,
I'm writing a lib to read, manipulate and save pdf xmp metadata. But did not find how to write the xml back to pdf. I'm sharing some code bellow, and I'll be glad if you help me with some example...
` export default {
}; `