Hi everyone!
Long-term objective: I would like to automatically remove user-specified pages from a large number of pdf files. To be more clear: let us say I have 10 different pdf files. For each pdf file, the user will individually input (into a table, see below) those page numbers which he would like to keep while the other pages will be deleted from the document.
I already found a JavaScript function which returns the total number of existing pages in a given pdf file. I also already found a JavaScript function which can delete a single page from a given pdf file at a time. Of course, this latter function can be used in a loop to remove multiple pages one after another.
Short-term objective: However, this requires two things (which I currently do not manage on my own):
- "Invert" the user-specified list of pages to keep into a pages to delete-list. For clarification: Let us say the user wants to keep pages 2, 3, and 5 out of a 6-page document. Then the pages to delete-list should contain 1, 4, and 6.
- Reorder the pages to delete-list in order to start with the deletion of the highest page number first. As the deletion is an iterative process, starting with the removal of page 1 would change all page numbers for the next page-removal iterations (which would make it very complex to keep track of the indices of those pages which should be removed). For clarity: this would turn our pages to delete-list from "1, 4, 6" into "6, 4, 1".
So in summary, the user should provide a table (Excel ...) containing the path to each pdf file in one column together with the list of page number he would like to keep (simply in the form of a comma-separated string containing those numbers such as "2, 3, 5") in another column. The function should then return the array "6, 4, 1" for a 6-page pdf document.
Please note: I am still free on the input format as long as the user can provide the information via a (Excel ...) table. So the list of pages to keep provided by the user could also be formatted differently.
Can anyone provide help here please? It is greatly appreciated!