PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jul 01, 2024 10:18 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Custom Metadata?
PostPosted: Mon Apr 23, 2012 1:54 pm 
Offline

Joined: Sun Nov 06, 2011 4:21 pm
Posts: 3
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom Metadata?
PostPosted: Wed Oct 09, 2013 2:15 pm 
Offline

Joined: Wed Oct 09, 2013 2:05 pm
Posts: 2
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom Metadata?
PostPosted: Thu Oct 10, 2013 9:14 am 
Offline

Joined: Wed Oct 09, 2013 2:05 pm
Posts: 2
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 60 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group