How to convert multiple word files in a folder to pdf?

Dear All,

I am new to RPA UIPath and want to understand UIPath by implementing simple bots. I want to build a bot which can help me to convert multiple word files in a folder to pdf? I have started the activity and for each item in Directory.GetFiles(“path”), what to do next?

Please help me in building 1st bot. Happy learning :slight_smile:

2 Likes

Hi
Welcome to uipath community
Hope these steps would help you resolve this
—use a assign activity like this
arrFiles = Directory.GetFiles(“yourfolderpath”)
Where arrFiles is a variable of type array of string

—then use a For each activity and pass the variable arrfiles as input and change the type argument to string in the property panel of for each loop

—inside the loop use Word package that go to design tab -> manage packages -> in official tab search as UiPath.Word and install that package

—now coming back to studio inside the loop use Word application scope and pass the input as item.ToString
—inside the scope use a activity EXPORT TO PDF where mention the file path to be saved with
This will convert all the word document in a folder to pdf files

Cheers @jaswinder_singh1

1 Like

Hi Palaniyappan,

Thank you for your help.

I have created a bot as per your suggestions but it is not converting every document.

Its converting only doc extension, not docx. Also, the document is not getting saved in the folder which i mentioned. instead it is taking folder name as file name and converting

1 Like

May I know how the Filename was mentioned
@jaswinder_singh1

Hi @jaswinder_singh1,
Try this

var files = Directory.GetFiles("C:\\path", "*.doc", SearchOption.AllDirectories).Union(Directory.GetFiles("C:\\path", "*.docx", SearchOption.AllDirectories));


Change the path and try.

Hi Palaniyappan,

Step 1) Assign
arrFiles = Directory.GetFiles(“C:\Users\acer\Desktop\word2pdf”) --> Where word2pdf is a folder

Step 2) For each item in arrFiles

Step 3) Body Word application scope
item.ToString()

Step 4) Do Export to PDF
“C:\Users\acer\Desktop\word2pdf”

Please check what mistake am i making?

Hi @shankm

Its throwing some error, not able to understand. what would the type of variable?

The type of variable files must be a string array.
And here we are filtering both the .doc and .docx file and adding it to an array.

What error is shown?
Can you share a screenshot?

Hi
here we need to mention the full path of the pdf along with the filename and the fileextension as .pdf
as you have left till word2pdf it has created the filename under the same
and as it is a EXPORT TO PDF activity even not mentioning the file extension it would have created on its own…

kindly mention the full filepath along with the filename and file extension
Cheers @jaswinder_singh1

Hi @Palaniyappan,

How do we mention filename and fileextension if you 3 different files for pdf conversion in the export to pdf path?

like this buddy
“C:\Users\acer\Desktop\word2pdf\”+Path.GetFileNameWithoutExtension(item.ToString)+".pdf"

Cheers @jaswinder_singh1

Ok @jaswinder_singh1,
Just add a .ToArray to the end of the line, like

Directory.GetFiles(“C:\path”, “.doc", SearchOption.AllDirectories).Union(Directory.GetFiles(“C:\path”, ".docx”, SearchOption.AllDirectories)).ToArray

Hi Bro,

Its working bro :slight_smile: Thank you for your quick reply :slight_smile:

Just one last help - I want all these files to be converted and kept under the folder? currently it is created in the desktop i.e outside of word2pdf , not inside of word2pdf

1 Like

Hi,

Its working bro. Thank you for your help :slight_smile:

1 Like

Awesome,
for doc file
kindly pass only one file path of word application scope directly and check whether that file from your folder is getting converted to a pdf, may be in a fresh sequence…apart from this

and

we need to check once the folder path like whether it is directing to desktop or to a folder

Cheers @jaswinder_singh1

A Bit technical :slight_smile:

Before writing this in export to pdf - “C:\Users\acer\Desktop\word2pdf”+Path.GetFileNameWithoutExtension(item.ToString)+".pdf"

Can i just create folder and then write above command so that the files are created under a folder

1 Like

@jaswinder_singh1
I think you missed a \ after the word2pdf in the path. Please check

“C:\Users\acer\Desktop\word2pdf\”+Path.GetFileNameWithoutExtension(item.ToString)+”.pdf"

Hi @shankm

Too good. its working now :slight_smile:

I can’t express my feeling that i created my first bot :slight_smile: and this was not possible without you and @Palaniyappan

All thanks to you guys. Happy learning :slight_smile:

2 Likes

No worries
Cheers @jaswinder_singh1