logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
richard  
#1 Posted : Monday, September 30, 2019 1:43:02 AM(UTC)
richard

Rank: Member

Groups: Registered
Joined: 5/9/2019(UTC)
Posts: 20
Australia
Location: Sydney

Hi Support,

We use the PdfDocument.Info dictionary to store some custom data.

After calling PdfDocument.Load(..), we noticed that some documents load with the PdfDocument.Info dictionary set to null. We would have expected an empty dictionary.

Is there anyway to create a new Info dictionary in the PdfDocument when its null (as we noticed the Info property on PdfDocument is readonly)?

Regards,
Richard
Paul Rayman  
#2 Posted : Monday, September 30, 2019 3:33:46 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 844

Thanks: 2 times
Was thanked: 103 time(s) in 101 post(s)
Hi,

Yes it is possible

Code:
var myinfo = PdfTypeDictionary.Create();
var list = PdfIndirectList.FromPdfDocument(doc);
list.Add(myinfo);
doc.Trailer.SetIndirectAt("Info", list, myinfo);


Now you can use the myinfo dictionary in the same way as if it were doc.Info.
When you save and then reload the document, this dictionary will be accessible through the doc.Info property.
Properties such as doc.Title, doc.Author, doc.Subject, etc will also work fine.

Code:
doc.Save(@"e:\copy.pdf", SaveFlags.NoIncremental);
doc = PdfDocument.Load(@"e:\copy.pdf");
doc.Info //not  null now;
doc.Title = "Title";

Edited by user Monday, September 30, 2019 3:36:56 AM(UTC)  | Reason: Not specified

richard  
#3 Posted : Monday, September 30, 2019 5:48:08 AM(UTC)
richard

Rank: Member

Groups: Registered
Joined: 5/9/2019(UTC)
Posts: 20
Australia
Location: Sydney

Awesome. Thank you for the prompt reply.

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.