RPA (Robotic Process Automation) is becoming increasingly adopted across various industries, a trend that shows no signs of slowing. Its meteoric rise in ubiquity in such a short timespan has spawned the creation of numerous automation vendors, eager to get a piece of the pie. With all the stiff competition, comes continuous improvements to the quality of RPA services provided, as well as a constant demand for new features and updates. Because of this, most RPA solutions offer a little bit of everything, but if your workflow demands handling documents and extracting data quickly and accurately, then a traditional forms processing solution is your best bet.
The good news is that most RPA solutions are easy enough to work with and robust enough to be able to integrate almost any third-party entity into your automated workflow; and we already know that Accusoft’s FormSuite is the king of structured forms processing. So to get the best of both worlds, here we’ll demonstrate how we can combine the forms processing that FormSuite provides with an automated business process implemented using UiPath.
And the best part is… NO CODING REQUIRED! Now before we get into the project itself, let’s set up the scenario that we are automating.
He’s fresh out of college with a degree in finance and is now the newest victim… I mean, intern… at TLL, Totally Legit Loans LLC: A legitimate loan establishment for legitimate people. As assistant to the loan officer, Todd is responsible for:
Sorting stacks of loan application papers that have been filled out by potential clients into three piles. These piles are for automobile loans, business loans, and student loans.
Scanning each pile of applications onto his work computer. (TLL is in the process of going paperless).
Reading each loan application and typing the applicant info into TLL’s very old (but totally legit) third party credit checking software, RiskE. Unfortunately, since there are three different kinds of loans he can encounter, there are three separate software programs he must interact with that correspond to each type of loan: RiskE Auto, RiskE Business, and RiskE Student.
After entering the applicant data, Todd must click the submit button. RiskE will show whether the applicant should be approved or denied a loan.
Todd then has to rename the file of each scanned application on his computer. The name should contain the loan application type, the applicant’s name, and whether they were approved or denied.
Finally, Todd has to sort the renamed files into separate “Approved” and “Denied” folders on his computer to be reviewed by the loan officer.
Yikes. Between the sorting, scanning, data entry, and file management, it looks like Todd has a lot of boring, tedious work on his plate. Let’s help him out.
What You’ll Need
FormSuite 5: Download and install the latest version for free right here. Make sure the installation goes to the default location. This should be C:\Users\Public\Documents\Accusoft
UiPath Community edition: Sign up for an account and install the software. Follow the instructions to download the UiPath Studio application. I used version 2019.8.0 when making this project but slightly older or newer versions should also work fine.
You are somewhat familiar with a typical forms processing workflow and FormSuite. If not, you can check out Accusoft’s forms processing overview. We’ll specifically be using the FormAssist GUI application that comes with the FormSuite installer. This will handle all of the forms processing stuff for this exercise.
You are familiar with what RPA is and what its used for. If not, you can check out our blog Introduction to RPA.
You are familiar with basic programming concepts such as flow of control, conditionals, loops, variables, etc.
How To Run the Project
Open UiPath Studio and open the project.josn file found in LoanApplication\LoanBot.
Near the bottom of UiPath Studio, click the Arguments tab and change the ProjectRoot argument’s default value to the path of where you unzipped your LoanApplications Folder.
Click the start button at the top left.
The project will start and open up the FormAssist application first. Once it has settled, it will be waiting for new image files to appear in LoanApplication\Incoming. You can copy some images from LoanApplication\FormSet\FilledImages into the Incoming folder and those files will be processed.
Need to programmatically convert HTML into PDF files? Going from one format to the next can be troublesome, and maintaining the correct layout and styles in the final document is often a complex challenge.
PrizmDoc API handles file type conversions smoothly and with no hassle. No installation, no servers to set up. Just use the API to upload a file and have it converted for you. For this demonstration, we’ll be creating a C# program that just requires the Newtonsoft.JSON package (which can be acquired via NuGet).
Once your account is set up, copy the API key. This will be used to authenticate your requests to the PrizmDoc server:
This demo will require the use of Newtonsoft.json package. If we’re using Visual Studio, just add this package to your project via the NuGet Package Manager:
The HTML To PDF Conversion Process
Converting a file using PrizmDoc servers is a 4 step process:
Upload: Upload the file to the server. We’re not making this a permanent part of the file portal – just putting it in temporarily while PrizmDoc does the work. When the file is uploaded, PrizmDoc returns a JSON response with internal file ID and an affinity token – we need both for the next step, which is conversion. See the PrizmDoc documentation on the Work Files API for more details ( http://help.accusoft.com/SAAS/pcc-for-acs/work-files.html#get-data ) .
Convert: Issue the conversion command on the uploaded file. Using the file ID returned from the Upload stage, our software orders PrizmDoc to convert that file to one of the supported file formats listed on the PrizmDoc documentation page. In this demo, we’ll just be converting an HTML file to PDF – but this program can be modified for a number of other file formats. Once a conversion process has started, the Conversion API provides a ProcessID that can be used to check the status of the conversion process.
The Content Conversion API documentation provides more details on how the process works ( http://help.accusoft.com/SAAS/pcc-for-acs/webframe.html#content-conversion-service.html ) .
Status: Until the conversion process is complete, we don’t want to try to download a file that doesn’t exist. The Content Conversion API as listed above also provides the current status of the file conversion with a ProcessID. Once the file conversion is complete, the Content Conversion API provides a new FileID of the converted file.
Download: Using the same Work File API with our new File ID and affinity token, we can now download the file.
And with that, let’s get coding!
HTML to PDF C# Code Sample
Here’s the C# code you’ll need to convert HTML to PDF using PrizmDoc. You can jump right into the code and run with it, or keep scrolling for a detailed walk through of the code and how it works.
In the sample project, there are a few housekeeping items to work through. The first is setting up the use of our API key. If you’ve downloaded our sample project, then edit the file config.json and insert your PrizmDoc API key like this:
In our sample project, the actual work is being driven by our PrizmDocConvert class. The first thing we do when generating the class is set the API key:
In our sample program, the API Key is read from our config.json file:
Step 1: Upload
The first part of our process is to Upload our file to the PrizmDoc server. Our member function really just needs one thing – the name of the file to upload, and it will return a JSON.Net JObject with the results:
The Work File API uses the POST command to upload the file, and requires the following headers:
Content-Type: This should be set to application/octet-stream since we’re uploading bytes.
The method uses the WebClient object to perform our uploading. So we set up the Work File API URI, and set our headers:
Then, read our file into a Byte object, and upload it to the PrizmDoc server using a POST command. The Work API will return a JSON response, which we can then parse for the next steps. In this case, we’ll upload an HTML file:
Step 2: Convert
Our uploaded file is sitting on the PrizmDoc server, all happy and content. But we want more than that – we want to convert it! In the last phase, the Work API returned a JSON file to us. Let’s peek inside:
If you’re familiar with JSON, then this should be simple enough. In our test application, we can snag the two fields we care about (the fileId and the affinityToken) with our JSON.Net objects. Our sample code uses another function to call our Upload method, but the final result is a JSON object with the Work File API results:
Now it’s time for the Content Conversion API to come into play. This API call requires a JSON file be posted with the details of what file is to be converted.
In this case, we’ll use our new method Convert to utilize that API with three parameters: the affinityToken, the fileID, and the format to convert to (which defaults to pdf):
We already covered how to add the headers to the WebClient object, so we won’t belabor the point. These are the required headers:
Content-Type: The type of file, in this case “application/json”
Accusoft-Affinity-Token: The Affinity Token we received from the Work File Upload
Acs-api-key: The API key
And our new URI will be “https://api.accusoft.com/v2/contentConverters”.
Our Convert request is in the form of a JSON file. We could submit requests for multiple files to be converted, but this demo will just focus on the one. Here’s the format of the JSON request:
Our method generates the JSON file this way.
There’s a lot of whitespace here, but it helps make clear what nodes of the JSON file belong to which parts.
All that’s left is to POST the JSON string:
The conversion process is started! But until it’s complete, we can’t download our completed file. So we need to request the Status until the conversion is complete.
For that, we need to know what the ProcessID is. The Content Conversion API returns a JSON file, of which the most important thing we need is the processID:
Step 3: Status
The Content Conversion API allows us to track the status of a conversion using the ProcessId returned from our Convert request. The URL is the same, with one major difference:
This is very important – this is a GET command, but don’t try to use the WebClient QueryString.Add member to add the processId. Your URI will not look like this:
It must look like this:
For example, a processID of ahidasf7894 would give use a URI of:
With that, let’s look at our ConvertStatus method, which will query the PrizmDoc server via the Content Conversion API. This API will return another JSON file for us to parse:
Our headers in this case are similar to before:
That’s it – since this is just a GET, and the Content Conversion API is getting the processId from the URI we request from, we just need to submit the request and return the JSON file:
Here’s a sample JSON file that will be returned:
What we’re looking for is for the “state” field to return “complete”. The sample code uses a 30 second wait timer after each Convert Status request. Once it sees the conversion is complete, it snags the new fileId that will be used to download the file:
And here’s the JSON file that returns the result we need:
Perfect. All that’s left is to extract the fileId:
Note that a Conversion Request can generate multiple files. For example, converting a multipage document into a series of image files. For more details, see the Content Conversion API documentation.
All that’s left now is to download our converted file with the Work File API.
Step 4: Download
We’re back where we started – the Work File API. This time, instead of uploading a file, we’re going to download the processed file. The URI is the same as before, with one change – the fileId of the file we’re downloading:
For our Download Work File method, we set up the method this way. The only new parameter is the outfile – this will be the name of the file we save the converted file to:
We use the same headers as in our Convert Status request:
Since this is a Get command, we just submit the request and pipe the results out to our file:
And with that, our program is complete! Here’s the results. In this case, the method calls are set to be verbose to track progression, but feel free to edit the program to your liking:
The converted document will retain images, lists, links, and other formatting and elements:
This program sample is just converting a simple HTML file – but if we were converting something like a Microsoft Word document, the results would be the same – a perfectly created PDF file. In fact, PrizmDoc uses Microsoft Word to process the Word Document conversion to have the highest possible fidelity.