PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Mar 29, 2024 9:40 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Jan 10, 2024 5:13 pm 
Offline

Joined: Wed Jan 10, 2024 4:18 pm
Posts: 1
I am attempting to add /PieceInfo to each page of existing PDFs. With type PdfString for Value parenthesis () wraps the value that ends up in the new Pdf.

I am attempting to add /PieceInfo to each page of existing PDFs. With type PdfString for Value parenthesis () wraps the value that ends up in the new Pdf. And \before and after the existing () are added.

What type and syntax is needed?

Looking to add this:
/PieceInfo<</Default<</LastModified(D:20231212073902-05'00')/Private<</DocID(122996605)>>>>>>"
Getting this:
/PieceInfo(<</Default<</LastModified\(D:20231212073902-05'00'\)/Private<</DocID\(122996605\)>>>>>>)

PdfLiteral also does not work because it wraps the Value with [].

The code:
PdfDocument PDFDoc = PdfReader.Open(input, PdfDocumentOpenMode.Import);
PdfDocument PDFNewDoc = new PdfDocument();
PdfPage pp = PDFNewDoc.AddPage(PDFDoc.Pages[Pg]);
PdfString ps = new PdfString("<</Default<</LastModified(D:20231212073902-05'00')/Private<</DocID(122996605)>>>>>>");
pp.Elements.Add("/PieceInfo", ps);
PDFNewDoc.Save(output);

Thanks.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 16, 2024 8:52 pm 
Offline

Joined: Tue Sep 30, 2014 12:29 pm
Posts: 36
I'd suggest creating the dictionary properly and not trying to "fake" it with strings or literals.

e.g.
Code:
var doc = new PdfDocument();
var page = doc.AddPage();
var privateDict = new PdfDictionary();
privateDict.Elements.Add("/DocID", new PdfString("122996605"));
var defaultDict = new PdfDictionary();
defaultDict.Elements.Add("/LastModified", new PdfString("D:20231212073902-05'00'"));
defaultDict.Elements.Add("/Private", privateDict);
var infoDict = new PdfDictionary();
infoDict.Elements.Add("/Default", defaultDict);
page.Elements.Add("/PieceInfo", infoDict);
doc.Save("out.pdf");


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 168 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