View Single Post
Old 10-19-2010, 01:43 AM   #10
frabjous
Wizard
frabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterfrabjous can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
frabjous's Avatar
 
Posts: 1,213
Karma: 12890
Join Date: Feb 2009
Location: Amherst, Massachusetts, USA
Device: Sony PRS-505
All right, here's my first attempt. Since I don't have access to mac, I'll need you to help me test it and tweak it. I should also mention that I'm not a programmer, just a power-user with delusions of minor scripting skills. So, fingers crossed.

I tried to make it work just using Ghostscript without pdfLaTeX, since Ghostscript is about 1/4th the size of a minimum LaTeX installation (and less than 1/50th the size of a full LaTeX insllation). I'd be much more confident of the script if it were written in LaTeX, but let's see if this works first.

Requirements:
  • BASH interpreter: this is the default shell language for mac and most linux distros, so if you're using one of those, you should be all set. (I have no clue whether or not this works with Windows w/ Cygwin, etc.)
  • calibre -- for its CLI tools
  • Ghostscript (for mac installation, see here)

Installing setting up the script:
  • Download the file pdfstretch.tar.gz attached below and extract the file pdfstretch.sh, which it contains.
  • Save it somewhere; either save it in your search PATH (if you know what means), or in the same folder with the PDFs you want to process.
  • Open a terminal, and type in:
    Code:
    cd "/path/where/you/saved/it/"
    replacing "/path/to/where/you/saved/it" with the actual location of the folder where you saved the script.
  • Type in:
    Code:
    chmod a+x pdfstretch.sh
    this will make the script executable.

(It's probably possible to do the above through your Finder or File Manager, but I don't know how on a mac. That should work, though.)

Using the script
  • Again, open a terminal.
  • Navigate to the folder containing the PDF files you want to process.
  • Type in:
    Code:
    ./pdfstretch.sh "my-file.pdf"
    ...replacing "my-file.pdf" with the actual name of the file. (Leave off the ./ at the start if you saved the script in your search path instead of the folder you're in.)

    This should process the file and create a new file named "my-file-stretched.pdf".
  • To process many files at once, you should be able to do:
    Code:
    for file in *.pdf ; do pdfstretch.sh "$file" ; done
    and have it process all the PDFs in a given folder.

Caveats:
  • Right now only the author, title and language metadata are preserved. This could perhaps be expanded upon.
  • It does not try to create 9cm × 12cm, but only files whose aspect ratios are 3:4, or close to 3:4 (and even then it isn't always exactly that, though it should be close).
  • I assume that Kindles and similar devices scale PDFs to fit on the screen, so that only the aspect ratio matters, not the actual page size, though I don't have a Kindle to test on. They may look very funny if printed, however. (Well, they look funny anyway.)
  • Files are auto-cropped to the minimum region possible without deleting anything besides whitespace. Some pages may end up smaller than others; only the biggest pages will be 3:4. Various e-readers may treat those smaller pages differently than others.
  • The squeezing/stretching is constant throughout the document. If you wanted shorter lines not to get squeezed, I think you're out of luck; PDFs do not know of "lines".
  • The script has not been extensively tested.

One cool thing about the implementation, however, is that the file is NOT rasterized. Text is deformed, but it's still text, so you can copy and paste, use dictionary functions, search, etc.
Attached Files
File Type: gz pdfstretch.tar.gz (1.4 KB, 340 views)

Last edited by frabjous; 10-19-2010 at 04:23 PM.
frabjous is offline   Reply With Quote