After some 2 hours of trying to get the string formatting right for the script, I have a working example for you and others who are interested in reducing size of PDFs
External Dependency : Ghostscript for windows (I used gs9.54.0 version)
In PowerShell this syntax can be used:
Start-Process "C:\Program Files\gs\gs9.54.0\bin\gswin64c.exe" "-sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH -sOutputFile=in_OutputPDFFullPath in_InputPDFFullPath" -Wait
In UiPath this is not that straight forward due to string formatting requirements.
The workflow will take the following arguments including the PDFSettings option.
I have annotations for them in the workflow, which you can refer. The important argument being the location of GhostScript (gswin64c.exe), yours may differ. Do change it before you run the attached workflow.
Since we are sending strings to PowerShell and in script format we check the IsScript
I added some FileInfo details of the input and output files, which you can use to verify if the reduction was successful or not. The output would look like
I have not included any exception handling in the PowerShell script or in the workflow, but I am assuming you can include them. I have a write up on creating error-proof workflow which you can refer.
Here is a sample workflow:
ReducePDFSize_Ghostscript.zip (248.7 KB)
I really hope you and others get good use of this workflow I sure did have some challenge getting this to work!