I am developing an application and i use the iTextSharp library.
I am also reading the iText in action from Manning so i can get references.
In Chapter 12 it has the following code to change the metadata in Java.
PdfReader reader = new PdfReader(src);
PdfStamper stamper =
new PdfStamper(reader, new FileOutputStream(dest));
HashMap<String, String> info = reader.getInfo();
info.put("Title", "Hello World stamped");
info.put("Subject", "Hello World with changed metadata");
info.put("Keywords", "iText in Action, PdfStamper");
info.put("Creator", "Silly standalone example");
info.put("Author", "Also Bruno Lowagie");
stamper.setMoreInfo(info);
stamper.close();
How can i do the same in C#?
Conversion from Java to C# is usually pretty straightforward. By convention, Java properties use
getandsetprefixes so to convert to C# you just need to drop the prefix and turn it into a .Net getter/setter call.getInfo()becomesInfoandsetMoreInfo(info)becomesMoreInfo = info. Then you just need to convert the native Java types to their equivalent C# types. In this case the JavaFileOutputStreambecomes a .NetFileStreamand theHashMap<String, String>becomes aDictionary<String, String>.Lastly, I’ve updated the code to reflect recent changes to iTextSharp that now (as of 5.1.1.0) implement
IDisposablenow.