If I have an existing document and want to add keywords to it there is no other way than using MergeDocument ? And since I want to save it to the same filename I guess I have to save it to a temporary file and then move/rename it to the original as it is used as a template?
add keywords to document
Re: add keywords to document
Support · May 27, 2014
Hello,
Yes, you will need to use the MergeDocument class of DynamicPDF Merger API to add any new contents to the existing PDF and there is no other way to add new contents to existing PDF without using MergeDocument class.
If you would like to save the merged output to same path as of input file with same file name then you will need to get the input PDF in the form of byte array or stream. Then load it using PdfDocument object and merge the PdfDocument object using MergeDocument class. Below is the sample code for it.
//Code to read the file into byte array.
byte[] pdfByteData = File.ReadAllBytes(@"C:\Temp\MyInput.pdf");
//code to load the PDF byte data.
PdfDocument pdf = new PdfDocument(pdfByteData);
//Code to merge PDF.
MergeDocument mergeDocument = new MergeDocument(pdf);
//Code to add new text using Label.
Label label = new Label("New content", 100, 100, 100, 20,Font.HelveticaBold,14,RgbColor.Blue);
mergeDocument.Pages[0].Elements.Add(label);
mergeDocument.Draw(@"C:\Temp\MyInput.pdf");
Thanks,
ceTe Software Support Team.