Is it possible to convert a excel file to PDF using UiPath


I’m new to Uipath and I have a task to copy the data from excel file into PDF. I have an excel file which contains data in table and image. Is it possible to convert excel file to PDF?. If yes, could anyone help me on this?


Hi @Dhanushree

Check the below post

Ashwin S

you can try this also,

1 Like


I want to convert using Uipath. Is it possible to convert excel file to PDF which also contain image?

Thank you.

use that powershell script to do the conversion. it will work for all kind of excel files. but you need to ammend few lines in the script.
try invoke powershell activity to trigger the scripts.

or use this utility to do the conversion. trigger through the command prompt.

I’m trying to use this in a workflow, but am not sure how to utilize the ‘Invoke power shell’ activity with UiPath. It works fine when I save it as a .ps1 file and execute with powershell, but I tried putting it into UiPath and it didn’t work.

I tried by putting the entire script into the CommandText input, made the TypeArgument System.Management.Automation.PSObject, changed all double quotes " to single quotes ’ and made sure the box IsScript was checked. Sometimes it runs fine with no errors. However, it will sometimes run the script and output the new PDF file as expected, but UiPath will throw an error with the following message: "Unable to cast object of type ‘System.String’ to type ‘System.Management.Automation.PSObject’. Exception Type: InvalidCastException.

Any ideas what portion of the script is throwing that error & how to get it fixed?

EDIT: I changed the TypeArgument to String as I was passing in two string arguments. This erased the PowerShellVariables I had already set up so I put them in again and it now seems to be working. My question is, why is it required & is changing the TypeArgument the correct thing to do in this instance? What would happen if my arguments I needed to pass to the power shell script were of multiple types?

EDIT 2: I just realized that it doesn’t work when trying to pass an argument, but does work when passing a variable. When passing an argument it gets an exception that the PDF file couldn’t be found. Not sure why it is throwing that error as it is supposed to be creating a new file, so of course it isn’t found! Any ideas? And anyone know why it works fine when passing a variable, but not an argument, even if they have the exact same value?

I attached a workflow - can someone else give it a try?
ExcelToPDF.xaml (8.0 KB)

You need to swap your argument values.


1 Like

Thanks, it’s so simple I thought I was going crazy! Whoops :blush:

1 Like

I am new to UIPath and I saw that these codes are interesting to convert excel to pdf

"$xlFixedFormat = ‘Microsoft.Office.Interop.Excel.xlFixedFormatType’ -as [type]
$objExcel = New-Object -ComObject excel.application
$objExcel.visible = $false

$workbook = $$ExcelFilePath, 3)
$workbook.Saved = $true
$workbook.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $PDFFilePath)


need help in explaining what each line of codes mean.

Thanks so much

1 Like

This is a powershell (PS) script that is executed by UiPath. I’ll do my best to explain what each line is doing. The overall goal is to create a PDF file that is a replica of an entire excel workbook.

  1. $xlFixedFormat = ‘Microsoft.Office.Interop.Excel.xlFixedFormatType’ -as [type]

This line defines the PS variable $xlFixedFormat as an excel FixedFormatType. This is the built-in method in excel to convert to PDF. See more info here: Workbook.ExportAsFixedFormat method (Excel) | Microsoft Learn

  1. $objExcel = New-Object -ComObject excel.application

This line creates creates a new object (excel)

  1. $objExcel.visible = $false

This line allows it to work in the background as I don’t want people interacting with it accidentally.

  1. $workbook = $$ExcelFilePath, 3)

Using the previously defined $objExcel, it uses the Open method with 2 arguments: $ExcelFilePath and 3.

  • $ExcelFilePath
    This is the full filepath of the workbook you’d like to convert, including extension. This needs to be an input PowerShellVariable in UiPath.

  • 3
    This means that any external links in the workbook should be updated on opening.
    The only required argument for the workbooks.Open method is the filepath. See the list of all optional argumetns here: Workbooks.Open Method (Microsoft.Office.Interop.Excel) | Microsoft Learn

  1. $workbook.Saved = $true

This saves the workbook you’ve opened. I included it because linked data being updated means the workbook may have changed. If you don’t update links, feel free to leave this out.

  1. $workbook.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $PDFFilePath)

This is where the actual conversion takes place. As mentioned before, excel has a built-in way to convert to PDF called ExportAsFixedFormat. The arguments supplied are:

  • $xlFixedFormat::xlTypePDF
    This specifies to convert to PDF (only other option is XPS)

  • $PDFFilePath
    This is the full filepath of where you’d like the newly created PDF file to be saved. Be sure the extension is included. This needs to be an input PowerShellVariable in UiPath.

  1. $objExcel.Workbooks.close()

This closes the workbook you’re working with.

  1. $objExcel.Quit()

This quits the excel application


Hi @Dhanushree, I have developed a custom uipath activity for this. You can install the package from Manage Packages in Uipath Studio by searching “ExceltoPDFConversionActivities” or directly download from the site and import it through the given link :
NuGet Gallery | ExceltoPDFConversionActivities 1.1.6

1 Like

I need some Carlyle for conversion of excel to pdf or csv to pdf … and what are installed manager packets and sample example …and above example i couldn’t understand which activates are you select… because i am new in the field…

Thanks bro. Solved a huge task for me.

Hi @Dave,

How to use with spesific sheets ?
I wanna try to export excel only sheets1 to PDF file ?

Can you help me resolve this?
Thank you in advance.

@Devi_Anisah this specific method would not be able to be used, as it will only convert the entire workbook. I can think of 2 ways I would try to go about it though:

  1. Make a copy of the workbook and delete all sheets except the one(s) you want, then use the powershell code in this thread to convert to PDF, then delete the excel copy you created. This is likely the quickest, easiest, and most reliable way to do it.

  2. Open the workbook (making sure it’s visible), navigate to the correct worksheet, then interact with the UI of excel to print the worksheet, changing the printer to ‘save as pdf’.

If your Excel file comprises contacts information, then I would suggest you to use Excel to PDF Converter to convert Excel file contacts into PDF on Mac OS X. The software allows to convert unlimited Excel file contacts into PDF in a single go without any hassle. So, go for it.

Anyway to do this with a word document instead of excel?

@Jesse_Mack - Please check this workflow… (71.3 KB)

FYI: I have use modern Projects…To get that go to settings → design → Use Modern for New projects…

If this is turned on you will get all new set of activities …for ex instead of Send hotkey you will see Keyboard shortcuts …etc etc…