Trying to extract page from multiple PDFs with ForEach loop (need help)

Hello, I’m new to UiPath and I’m trying to make some demo processes to show the software to my co-workers to see if it is something we can use in our environment. I’m trying to create a process that will look at all of the PDF files in a directory and then run a for each loop on each to extract a specified page. I’m getting the below compile error. I think I’m using the wrong variable type but I can’t seem to find a type that will work. Any help is appreciated.

Hi @mrice1982

Can you try passing ‘file’ to the “Extract PDF Page Range” activity?

Let me know if this works

1 Like

Thanks for the help. I had tried that before and was getting a different compile error. I tried changing it back and got the below error. After some googling I was able to get the variable types matched up in a way that does not result in any compile errors but when I run the process it only extracts the page from one of the PDF files in the directory instead of all of them. Any ideas?

Glad it worked.

What do you have set as the ‘OutputFileName’ property?

1 Like

Hi @mrice1982,

Try changing the TypeArgument of the for loop to String:
image

I have had similar issues in the past and would keep forgetting to change this. Let me know how that works :slight_smile:

2 Likes

@mrice1982

I was also reading somewhere that in order to loop through PDFs, you need the paid version of UiPath. Not sure if that still is true, but maybe something to look into.

1 Like

I have a file path to a non-existent PDF. I was hoping the process would create the PDF and add the extracted pages. It does create the PDF, but it only includes the PDF from the second PDF in the folder (there are only two in the folder I’m looping through).
image

Hmm, that’s odd, maybe that is what is going on. Thanks for your help with this. Got me closer to a working process anyway.

@mrice1982

My guess as to what’s happening is it overwrites the previous file when adding the second page.
Could you try creating separate files with a wildcard file name and then combine them with another activity?

1 Like

Thanks, this was part of the problem. After setting this and making a couple of other changes I was able to get it working kind of. Just doesn’t seem to be doing exactly what I was expecting.

1 Like

I think you are right about the overwrite. Not sure how to use a wildcard file name. Do you mean change the OutputFileName path to include a wild card like the below? All that did was create a file with the wild card in the name. Is there a different way to do it?
image

In your For Each activity, assign the output variable:
forEachLoop

Then in your file path it would be something like:

“C:\Users%yourUser%\Desktop\UiPathDemo\PDF\extractedpages” + %outputVariable.ToString% + “.pdf”

2 Likes

Dude, you’re awesome, this is working. Thanks so much for your help. I did end up having to install the PDFSharp package and the UIPathTeam.PDF.Extension.Activities to do the merge but it is working now. Below is my complete process.

1 Like

Glad I was able to help :smile:

@mrice1982 glad to hear you got it working!

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