How To Convert An Excel File Into A PDF File?

To convert an excel file to PDF using UiPath Activities. The Excel file has multiple columns, but while converting , it is not possible to get all the columns in a single page in the PDF. How to get all columns in a single PDF page?

Issue Description: To convert an excel file to PDF using UiPath Activities. The Excel file has multiple columns, but while converting , it is not possible to get all the columns in a single page in the PDF. How to get all columns in a single PDF page?


Resolution: There is no out-of-the-box solution for this, but there are some development approaches one can follow,

Approach #1 :

  1. Use Read Range activity to read data from Excel and will give you output as Datatable.
  2. Then use Output Datatable activity and it will convert Datatable to string.
  3. Then use Word Application Scope activity and write that data into it. And also use Export to PDF activity inside Word Application Scope and it will convert that document into PDF file. Refer Save Document As PDF .

Approach #2: Use custom projects from the UiPath Marketplace. Refer Excel To PDF Conversion.

Note: Marketplace components are not officially endorsed or supported by UiPath. Please contact the project creator for support.

Approach #3:

Write code in C# or VB for the conversion and use Invoke code activity in the workflow.

Approach #4 :

Create a custom activity. Refer Activities .

After trying MANY different approaches, I’ve found that the most reliable and clean method is using a VBA macro with Invoke VBA, combined with UiPath’s Save as PDF activity.

Step 1 - Create a Excel Process Scope.
Step 2 - Create a “Use excel file” activity targeting your excel file.
Step 3 - Create a Invoke VBA activity" targeting your excel file. Create a .txt file with the following script:

Sub ResizeSalesReport()
    With ActiveSheet.PageSetup
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
        .Orientation = xlPortrait  ' or xlLandscape
    End With
End Sub

Step 4 - Set the parameter “Code file Path” to the script file and the “Entry method name” parameter to “ResizeSalesReport”.

Step 5 - Create a Save Excel File as PDF activity

Example Image: