SaveOptions.e_remove_unused

Does “SaveOptions.e_remove_unused” also remove duplicate resources that could potentially occur during a PageInsert()? In that case they are not unused but there is no need for duplication so does the API treat the duplicate as unused and remove that too?

The “SaveOptions.e_remove_unused” flag only removes objects that are not referenced in any part of the document. If InsertPages() creates duplicate resources, they will most likely be referenced by the page that is now part of the PDFDoc, and therefore are used by the document.

If you would like to remove duplicated resources from the PDF, you can run the PDFDoc though the Optimizer class, which removes unnecessary/duplicated data.

So the answer is NO. Right? It will not remove duplicate references.

I ask because I was thinking of using InsertPages() instead of ImportPages(). ImportPages() does not import duplicates but it is harder to use because it does not keep page order. InsertPages() inserts duplicate resources but keeps page order. If “SaveOptions.e_remove_unused” would remove duplicates then together with InsertPages() would be a complete and simple solution. But if it doesn’t then running the optimizer which requires an extra license makes no sense, so in that case ImportPages() with the extra work of reordering the pages makes more sense. Right?

Sorry for the delay in a reply.

The advantage of ImportPages, and to get the most out of it, is that you pass all the pages you want to import in one go, so that PDFNet knows the minimal set of resources to import (avoiding duplication).

The returned array should be in the same order that was passed in, so handling the ordering afterwards should be straight forward with some additional mapping on your end.