Tech Blog

Creating a Migration-Tool Split Plug-in

Rosetta 4.0 uses migration-tool plug-ins to generate derivative copies (instead of the legacy stream handlers). These plug-ins are used by Transformation Profiles (another 4.0 feature) which allow users to determine a many-to-one (merge) or one- to-many (split) relation between the original file and the derivative copy, in addition to the one-to-one relation, supported by the stream-handler based process.

This post explains how to create a migration-tool plug-in that splits multi-paged file into individual JPG files, one per page. Typical use cases can be where you want to use the IA Book Reader to deliver your PDFs (since the reader displays JPG files) or create individual JPG files from a multipage TIFF file.


Creating the script

The migration-tool plug-in has a script interface. Being a split plugin, the last two parameters are reserved for the input filename and the output directory name, respectively. We’ll can add any output filename with a jpg extension, relying on Imagemagick convert’s behavior that adds a sequence to the output files:

>pdfinfo test.pdf | grep Pages

Pages:          5

>convert test.pdf out/test.jpg

>ls out

test-0.jpg   test-1.jpg  test-2.jpg  test-3.jpg   test-4.jpg

The script, therefore, looks like this:


# wrap all but the last two parameters
for (( i=1;$i<$#-1;i=$i+1 ))
    ARGS="$ARGS ${!i}"

mkdir -p $OUTPUT_DIR

convert $INPUT_FILE $ARGS $OUTPUT_DIR/derivative.jpg

exit $?

The $ARGS will include any convert options I’ve defined as parameters in the Transformation Profile, e.g. quality, resize, etc..

Leave a Reply