How to save with e_remove_unused but preserve the PDF version number already in the file?


I am trying to save a PDF-File with version 1.5 by calling PDFDoc.Save(SaveOptions) with SDFDoc.SaveOptions.e_remove_unused as parameter.

I realized that the version of the PDF-File has changed to 1.7 but I need it in 1.5.

Saving the PDF-File without any SaveOptions doesn’t change the version of the PDF, but I need PDFNet to remove unused objects.

PDFDoc doc = new PDFDoc(inputFilePath);
byte[] docAsByteArray = doc.Save(SDFDoc.SaveOptions.e_remove_unused);



You can drop down a level in the API, and use SDFDoc.Save, which allows you to enter your own version number. A PDFDoc ISA SDFDoc so this is fine.

byte[] docAsByteArray = doc.GetSDFDoc().Save(SDFDoc.SaveOptions.e_remove_unused, "%PDF-1.5");

Please see these posts for more info.