Hey, General I am new to working with pdf, and specially on this metadata level, so bear with me.
We uses PdfSharpCore 1.3.43 (I know this is a port of the PdfSharp lib, but if it is doable is your lib, I can probably transfer it to this one).
Because of another 3rd party library, we need to purge certains elements from pdf documents, that is not part of a specific whitelisted set. For now these are:
- /Pages/
DefaultValue- /
AcroForm/ -> this one always contains a single "/Fields" that is an empty array
Example of the structure of one of the documents
The "/Pages/DefaultValue" was easy to remove. But I dont know how to completely remove the "AcroForm" completely from the pdf?
- My initial thought was to remove alle the attributes under the "/AcroForm/", which only contains an empty array "/Fields", but that didnt work.
Any ideas of how to achieve this in PDFsharp?
Code I am working with so far:
Code:
PdfDocument pdfSharpDoc = PdfReader.Open(memoryStream, PdfDocumentOpenMode.Modify,
PdfSharpCore.Pdf.IO.enums.PdfReadAccuracy.Moderate);
pdfSharpDoc.Pages.Elements.Remove("/DefaultValue");
pdfSharpDoc.AcroForm.Elements.Remove("/Fields"); // Doesnt work, removes the element but doesnt remove the AcroForm from the the file.
PdfCustomValues.ClearAllCustomValues(pdfSharpDoc);
There seems to be a fork of the PDFsharp nucketpackage that has implemented this in a Flattern method, but we cannot use the .NetFramwork lib.
https://github.com/packdat/PDFsharp/blo ... nt.cs#L905Thanks in advance.