I am working on PDF portfolio documents, where I want to modify every pdf file in the portfolio. These files can be found under Document.EmbeddedFiles collection(as FileSpecification classes).
FileSpecification.Content is the stream for the document content, and it has both getter and setter. However, whatever I do with this FileSpecification object (such as fileSpecification.Content = processedStream), and save the document(Pdf.Document) somewhere; I cannot see any changes on the file itself. As a workaround, I delete and add FileSpecifications to EmbeddedFiles collection with the following code, and it works.
for (int i = document.EmbeddedFiles.Count; i > 0; i–)
FileSpecification embeddedFile = document.EmbeddedFiles[i];
var processedStream= Process(embeddedFile);
var filename = document.EmbeddedFiles[i].Name;
var description = document.EmbeddedFiles[i].Description;
document.EmbeddedFiles.Delete(i - 1);
document.EmbeddedFiles.Add(new FileSpecification(processedStream, filename, description));
This works alright, but doesn’t look right one bit. If there is a way to modify the pdf files under portfolio that’s what I’d like to learn. Otherwise, I think “fileSpecification.Content = processedStream” should change the content when the document is saved.