Skip to main content
Nintex Community Menu Bar

How to convert docx files to PDF using Kryon RPA

  • August 31, 2022
  • 0 replies
  • 156 views

MillaZ
Nintex Employee
Forum|alt.badge.img+22
Product: Kryon RPA
Product Version: 19.1 & above
Components: Kryon Admin; Kryon Robot; Kryon Studio
Article Contributors: Zakir & Clinton
Some time user will feel need to convert all their docx files into PDF format to share with internal or external clients so that users won't be able to modify it.

Prerequisites:- Need to have MS office and PDF viewer tool to verify input and output - Kryon studio access
 

Steps:

Using Powershell code
How to utilize above code in Kryon

 


Using Powershell code

1- First of all there are other ways we can achieve this but we selected Poweshell because this utility is already available on each Windows OS. So user doesn't have to do further changes in wizard on other machines (like robots) to achieve the result.

2- Below is the code snippet which we will be using in our Kryon Studio wizard:
 

$Files = Get-ChildItem "C:	emp	emp1docs*.docx" $Word = New-Object -ComObject Word.Application Foreach ($File in $Files) {    # open a Word document, filename from the directory    $Doc = $Word.Documents.Open($File.FullName)     # Swap out DOCX with PDF in the Filename	  $Name=($Doc.FullName).Replace("docx","pdf")     # Save this File as a PDF in Word 2010/2013    $Doc.SaveAs([ref] $Name, [ref] 17)    $Doc.Close()}

 

3- Short Explanation of code:

    - in $Files variable, we are getting all "*.docx" files present in folder "C: emp emp1docs""
    - $word variable is to store an instance of word application
    - in foreach loop we are converting all docx files to PDF files.

4- For detailed explanation please follow below link :

https://devblogs.microsoft.com/scripting/weekend-scripter-convert-word-documents-to-pdf-files-with-powershell/

 


How to utilize above code in Kryon

 

 

 

 

Note: In above code please notice "$" sign, which Powershell uses to denote a variable. Now in Kryon also we use it to utilize declared $Variable_Name$. So we will have to take care of it during wizard creation.​

 

 

 

 

Wizard creation steps:

1. Assign "dollar" variable a "$" sign.
 

23909i1A96471A32E0D04B.jpg

 

2. Take code mentioned in section 1, into a variable "mycode".
Notice that all dollars sign from above code in section 1 are replace by our variable like this "$dollar$".
 

23910iD78BA14AA1689F05.jpg

 

3. Now create new text file with custom file extension i.e. "ps1". This is nothing but we are creating a powershell command script file.
once you will execute the whole wizard this will be saved in %temp% folder. Please check 2nd screen shot in this point.
 

23911iF62BCDAC361FD828.jpg

 

23912i6DD551848E13C6FB.jpg

 

4. Now write "mycode" into newly created "ps1" file.
 

23913i6D7B9471C3A6DB6D.jpg

5. Use RUN advance command to run powershell script as follows. Please note here to check
"Wait for program to finish".

 

23914i630B90FCAD136059.jpg

 

6. Take the result in a variable "myoutput" is shown in above pic and use Message box AC to show the output.
7. This is how your full wizard will look like.

 

23915i1E07AFD2BDF2BFCA.jpg


8. Now when you will run the code msgbox should show "0", this means code ran successfully.
 

23917iC3A476E0571BCD14.jpg

9. Once code execution finished go and check your folder, you will be able to see all docx files now having their PDF version.

 

23918i883082C86D005170.jpg

 

More Information: https://devblogs.microsoft.com/scripting/weekend-scripter-convert-word-documents-to-pdf-files-with-powershell/