I need to delete the second page from each PDF in a folder before the PDFs are digitized and data is extracted. The PDFs vary in length so sometimes it’s page 2 of 2 that needs to be deleted, sometimes page 2 of 3 or page 2 of 4, etc. The pages do not have page numbers.
I installed the UiPath.PDF.Activities package and currently have the step set up to delete the last page (previously thought we needed last page deleted but turns out we need the 2nd page of each file deleted).
You don’t need the Write Line, it’s just for logging the page count to the Output panel. In general when you want to do that you should use Log Message.
You don’t need the splitting logic others have suggested. You don’t even need the Get PDF Page Count. The Extract PDF Page Range activity will accept a value such as "1, 3-End" which will do what you need.
However, I’m not sure what it’ll do if you put “1, 3-End” for a document that only has two pages. If it faults then keep the Get PDF Page Count and use this in your Range:
If(PageCount>2,"1, 3-End","1")
That means if the page count is more than 2 use the "1, 3-End" range, otherwise just use "1" for the Range.
Range - The range of pages that you want to retrieve. You can specify a single page (e.g. “7”), a range of pages (e.g. “7-12”), or a complex range, (e.g. “2-5, 7, 15-End” or “All”). Only string variables and strings are supported. By default, this field is cleared.