Monday, August 11, 2008

Using Watched Folders to Convert PDF files to DOC with Solid PDF Tools

Using the scripting functionality of Solid PDF Tools Scan to PDF to watch a folder for PDF files and automatically convert them to DOC is fairly easy.

Microsoft provides a .NET class in System.IO called FileSystemWatcher which takes care of watching a folder. Any time a PDF file is moved or copied into the watched folder an event will be raised. Add an event handler to run a script with Solid PDF Tools and you're done (this is a simplification, but most of the other work is just implementation).

We have created a C# project [solidwatcher.zip] which provides a good example of how to do this in a command line program. A basic outline of the project is below:



There are two main sections. The first is the Main() method that is run when you run the program (solidwatcher.exe). The second is the event handler that handles events that are raised when files are copied into the watched folder.

There are about fives lines of code in the Main() method that you need to understand. The highlighted code below shows creating the FileSystemWatcher object and getting the path for the watched folder from the first argument on the command line.



The highlighted code below allows us to filter based on file name (anything ending in .pdf in this case). The next highlighted section lets the end user running the program know that it is running and loops until they press the 'q' key and enter.



Although the event handler in the project is over twenty lines of code, you really only need to understand three of them (highlighted below) to understand what is going on.

First, we make the script. After that we create a new SolidScript object and run it's RunScript method with the script you just created.



If you're new to scripting Solid PDF Tools you may wish to look at our scripting reference and our first post on scripting using Solid Documents software.

0 comments: