Tuesday, August 12, 2008

Using Watched Folders to Convert PDF files to PDF/A with Solid PDF Tools

Our last blog post showed how to write a command line application that watches a folder for PDF files and converts them to DOC. Due to the flexibility of scripting Solid PDF Tools Scan to PDF we can adapt this to other needs very easily.

For example, say you want your watched folder to convert PDF files to PDF/A-1b. Why would you want to convert PDF files to PDF/A? Because converting to and validating PDF/A files will help to ensure that they are archivable and will display the same now as they will in 40 years.

With a few minor changes to the script you now have a program that watches for PDF files and converts them to PDF/A:



The rest of the changes in the PDFAWatcher project [zip file] are just in implementation (e.g. checking to see if the folders that the original and converted files will be placed in exist and creating them if they do not).

If you want to adapt this project for your own needs you may wish to look at our scripting reference and our first post on scripting using Solid Documents software.

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.