Post Top Ad

Your Ad Spot

Feb 23, 2018

Fixed issue with Ghostscript

Some days ago, I wrote that Icaros' new PDF to PNG option would have worked only if paths and file names had no spaces, and this was due to a precise Ghostscript 8.50 limitation (no spacing allowed; and it does not accept paths surrounded by commas, neither for the input file name, nor for the output one). My initial approach was setting up a Dopus5 action with a command like this:

gs -sDEVICE=png16m -sOutputFile={ou}-p%03d.png {f}

(and some other more or less important switches I don't mention here). If you have ever read Dopus 5 user manual, you should know that once this action was applied to a file name, it would have meant something like:

gs -sDEVICE=png16m -sOutputFile=FILENAME.PDF-p%03d.png THE:PATH/TO/FILENAME.PDF

So, nothing wrong when your input file is something like sys:Pippo/Pluto.pdf

gs -sDEVICE=png16m -sOutputFile=Pluto.pdf-p%03d.png sys:Pippo/Pluto.pdf

but what if your file name included spaces? Let's imagine your pdf is sys:Pippo/Report about 2017.pdf. The resulting command line would have been:

gs -sDEVICE=png16m -sOutputFile=Report about 2017.pdf-p%03d.png sys:Pippo/Report about 2017.pdf

and ghostscript would have interpreted it like this:

gs | -sDEVICE=png16m | -sOutputFile=Report | about | 2017.pdf-p%03d.png | sys:Pippo/Report | about | 2017.pdf

This line would have de facto included 4 unexpected/wrong arguments: about; 2017.pdf-p%03d.png; about and 2017.pdf-p%03d.png. And this explains why the action on some files wouldn't have worked. And no, as I said, using "sys:Pippo/Report about 2017.pdf" wouldn't have worked as well.

So, the solution I found to this problem deals with two potential issues: a space in the sub-directory path, and a space in resulting PNG names. The former issue has been worked around by temporarily copying the pdf file to the RAM Drive, giving it a fixed short name like T:PDFFILE. The latter has been resolved processing the source file name with gsar, removing all spaces. In the future I will improve this search & replace job by adding also other characters Ghostscript does not like. I implemented all this with my old PoorPDF trick (do you remember?): I just respawn the procedure but, instead of showing all images on the screen like I did in the past, I rewrote the script to act like a simple converter, asking the user where to put all PNG images. So, here's what's new on Icaros today:

1. I implemented a poorpdpng command in C: which accepts a file name to open (your PDF file), stores it into a temporary variable and executes a script

2. I wrote the sys:Tools/PoorPDF/PoorPDF2PNG script which a) gets the file name from the variable; b) copies the source PDF file to t:tmppdf; c) cleans the original filename from spaces; d) asks the user where to put output images; e) converts the PDF pages into 150dpi PNG images using the right names.

PoorPDF2PNG asking user where PNG images should be placed

Et voilà. Now spaces are not a problem anymore. By the way, since I was at converting things, I decided to implement also a MOD to WAV/IFF converter. I found on Aminet a program for 68K called "mod2wav" which included sources, and I decided to try building it for AROS too. Thanks to its author Martin Cameron, it worked like a charm with a single 'make' hit. I uploaded it to the Archives too, and it should appear in the next hours. Now Dopus5 has also a "MOD > WAV" option for module songs, and new dafault action for them will be playing with mikmod player, which will be added to sys:Utilities drawer.

Post Top Ad

Your Ad Spot