PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Custom Metadata? https://forum.pdfsharp.net/viewtopic.php?f=2&t=1983 |
Page 1 of 1 |
Author: | Derek [ Mon Apr 23, 2012 1:54 pm ] |
Post subject: | Custom Metadata? |
Hello, Is there a way to embed custom metadata strings into a PDF created with PdfSharp? For example, I want to embed CustomProperty1="String1" CustomProperty2="String2" I would then need to read those properties at a later time. Thanks in advance |
Author: | bartekj81 [ Wed Oct 09, 2013 2:15 pm ] |
Post subject: | Re: Custom Metadata? |
Hi guys, This is my first post in here. I want to attach my question to this topic. I know how to create new Custom Properties fields in PDF (below): PdfDocument document = PdfReader.Open(OutputFile); document.Info.Elements.Add(new KeyValuePair<String, PdfItem>("/CustProp01", new PdfString("TEST01"))); document.Info.Elements.Add(new KeyValuePair<String, PdfItem>("/CustProp02", new PdfString("TEST02"))); document.Info.Elements.Add(new KeyValuePair<String, PdfItem>("/CustProp03", new PdfString("TEST03"))); document.Info.Elements.Add(new KeyValuePair<String, PdfItem>("/CustProp04", new PdfString(""))); document.Info.Elements.Add(new KeyValuePair<String, PdfItem>("/CustProp05", new PdfString(""))); document.Save(OutputFile); Please, note that while I am adding new Custom Properties, I can add also their values - and they are visible later after opening a PDF file. But I don't know how to update existing Custom Properties?? No matter what I am doing - they don't want to go in. I tried to use below code (SetValue) - but it doesn't work: PdfDocument document = PdfReader.Open(newOutputFile); document.Info.Elements.SetValue("/CustProp01", new PdfString("TEST01"))); document.Info.Elements.SetValue("/CustProp02", new PdfString("TEST02"))); document.Info.Elements.SetValue("/CustProp03", new PdfString("TEST03"))); document.Info.Elements.SetValue("/CustProp04", new PdfString(myvariable01))); document.Info.Elements.SetValue("/CustProp05", new PdfString(myvariable02))); document.Save(OutputFile); No matter if I use user text or calculated variable - it doesn't update the file. Am I using wrong options (command) to update existing Custom Properties? Guys, please help as I have stuck with this for last two days and I can't find any info how to update existing custom properties using PDFSharp. Best Regards, Bartek |
Author: | bartekj81 [ Thu Oct 10, 2013 9:14 am ] |
Post subject: | Re: Custom Metadata? |
Guys, I found the reason why it didn't work: In the previous post you could see that I was opening and updating fields in newOutputFile, while at the end I was saving OutputFile. This couldn't work obviously even if the data was properly updated. PdfDocument document = PdfReader.Open(newOutputFile); document.Info.Elements.SetValue("/CustProp01", new PdfString("TEST01"))); document.Info.Elements.SetValue("/CustProp02", new PdfString("TEST02"))); document.Info.Elements.SetValue("/CustProp03", new PdfString("TEST03"))); document.Info.Elements.SetValue("/CustProp04", new PdfString(myvariable01))); document.Info.Elements.SetValue("/CustProp05", new PdfString(myvariable02))); document.Save(newOutputFile); So if anyone wants to know how to update existing custom properties - this is the answer. Just use .Info.Elements.SetValue property. Regards, Bartosz |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |