How to delete second page from PDF?

Hello,

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).

Screenshots below:




OutputFileName: file.ToString + “_Page_Extracted.pdf”
Input Range: (PageCount-1).ToString

Do I need to approach this a different way? Can I just alter the Input Range somehow?

Thank you for your help!

Split the document. (native activity in the UiPath.pdf package)
Split it 2 times so you have 3 separate documents.

  • Page 1
  • Page 2
  • rest
    Maybe count the pages up front to avoid impossible splits.

Then merge Page 1 and the rest into a new doc, which will be the same as your source without page 2.

1 Like

Hi @Laura_Hubbard ,

I have replicated your Scenario and built a workflow
You can add your pdf file name in Data/Input location
And see the magic

What i have done

  • Split the pdf page wise
  • ignore the 2nd page while splitting
  • Join the splitted pdf and is placed in Data/output location

Please find the workflow below
PDF_Splitter.zip (25.2 KB)

Hope it helps you out!

1 Like

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.
1 Like

Thank you all for the suggested resolutions!

@postwick, I used the Range you suggested (If(PageCount>2,“1, 3-End”,“1”))and it worked.

Thank you for the documentation link as well!

-LHub

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.