Watch our video to learn how to create a Custom Export Script in ABBYY FlexiCapture. Custom export scripts allow you to perform various tasks some of which include exporting a document to a PDF archivable (PDF/A) format, creating database calls, web service calls, and other API calls. In this demo you will learn how to create a custom export script that exports a document to a PDF/A format.
Hello today, I’m going to show you how to create a custom export script. Now, there are times in the workflow of a FlexiCapture project that we want to do something custom, or maybe we want to call a web service API, or maybe we want to write to a custom database in a custom format that maybe isn’t supported out of the box. And the way that we do that within the solution is by using a custom export script. What we will do is we will open up the document definition via the project menu. We’ll edit it. And when that opens, we will go to the export settings at the top left. For today’s demo, we’re going to add a new export setting. The type in this case will be a Custom export (script). And we will just simply for cases of testing today, we will just say, the errors are irrelevant.
Now this is really something that you need to control based on your project, but not really the point of today’s demo, but you know, obviously set the setting to be the proper condition based on your project needs. You’ll see, the first thing then that happens is we get a script. This script has a couple of things that we have access to. We have access to a document object. We also have access to a processing object. Now for today’s demo, I’m going to kind of show you maybe a best practice and how to write this script. Now I’m going to show you this script, but I want you to realize that you can do whatever you want here. My script is going to export the document to a PDF archivable format, what we call a PDF/A format. You can write this script to do whatever you want. You can call a web service call. You can write your own custom database call. You can call other APIs, but that’s what we’re going to do today is just simply export the document to a PDF/A, which is actually supported out of the box, but for today’s demo, we’re going to script it.
So one of the things that I like to do is I always like to use formal and good programming to do such a thing. So typically what we want to do is we want some sort of try catch. So the reason why is we want the software to attempt to do something. And if there’s a failure, we’re going to allow the software to fail nicely. So I would write something like this.
And so that’s a very good way to kind of set up our script here. In this case, I’m going to do a couple of things. I’m going to just copy in some code just to prevent you from having to hear me type for a bunch of code here. And what we’re going to do is we’re going to export this document itself to a PDF/A. We’re going to give it a path and we’re going to move on. Now, a couple of other things that you should know is that not only do you have access to a document object and processing object, but you also have access to all sorts of cool things that we can do in the export settings. So in this case, I’m exporting to a PDF/A, as I’ve told you, and you can see, I have access to this export images saving options object here.
And if you would like to know more about some of these settings, if you go to your start menu and you go to the Developer’s Help, this will be able to tell you. So for example, the Developer’s Help is very, very strong within the solution. So if you need to know more about a specific object, all you gotta do is search for it. And you’ll be able to see all of the methods and properties available to you. Also, there’s a lot of options that are documented well online. So in this case, we’re going to try to export to a PDF/A. If that fails, then we want to do something smart with it. We want to be able to tell the software through the software’s methods, how to report an error if it fails and how to clean it up well. And what happens here is we have access to a processing object.
And so what we would do is we would do something like this. We would call it a processing object and we would report an error. When we report an error, this will tell us, and more specifically, the processing server will report an error for this task. That’s a very important piece that we’ll come back to here in a second. And maybe in this case, we would want to do something very cool. Like maybe, you know, tell the log that there was a processing error during export and report the error on here. Some other things that we would do as a best practice is, use this processing to do some additional debugging or to note when a process starts and stops. So within that processing object here, we may report an error or a warning or a message. It’s very common that we would use a message. And here’s an example of one where, you know, maybe we want to add a message in the log that says when the export was started and maybe when it was ended. And you can just take your imagination from there and start customizing any sort of messaging that you’d want for maybe even debugging purposes as part of your script.
Now, this would be a very common way that I would write a script. We would do a try catch. We would use the processing object to report messages to and from the processing server log. And we would access the document object in this case to do something intelligent. And you can see here, I’m saving this document as a PDF/A. So pretty standard. I’m going to export this document to this path via my export script. I will save this and I will finish up exporting the export settings there. We’ll go ahead and save our document definition. And then of course, like always we will publish it.
What I’m going to do now is actually run a document into the software. We’re going to open it up in a verification queue. And then what we’re going to do is we’re going to watch the export happen via the processing server application.
So I’m just going to go ahead and send up a document. Now, here at UFC, we have this neat little tool that allows you to right, click a file and send it to ABBYY FlexiCapture. That’s not the purpose of this demo, but if you’re interested in this tool, feel free to reach out to us. So I’m just going to tell the software what project to send this up to. We’re going to get that document into the solution. As you know, when we have a working batch in this case, it’s going to go to a verification queue when it’s ready for us to review. So therefore I will open up our Verification Station to review this document.
Now that we have the document in the queue, I’m going to simply just come in here. I’m not even going to look at the document. I’m going to close a task. And as you know, in a common workflow, that typically means we’re going to export this document. So I’m going to hit close task. And the important part that I want to show you is that from now on, we will have a task for that export and you can see here, it’s now been exported and I wanted to show you something. You may remember that I put in some processing report messages for debugging purposes that tell me when an export is started and stopped and ended. And those were the report messages via the processing object. Also this document, then succeeded and you can kind of see that here. I’m just actually going to show you the example file.
So if I open up my sample export. There, I have my test PDF as a PDF/A format. So once again, always use a very good scripting practice. This is a copy of the script here in notepad, but just remember you want to use, try catches cause you want to clean up errors as well. You also want to use the processing objects so that you report back to the software cleanly when there’s an error or when there’s messaging, or even in this case, there may be a warning instead of an error. And all of that is available to you via the scripting language. And please always remember to reference the help. The help is your friend, in this case. Use it. Get familiar with how to navigate it based on the methods or properties that we want to associate with our scripting. I hope you enjoyed this video. If you have any other questions, please reach out to us. Thank you so much.