Tag Archive: “pdf”
Save PDF Pages as Images
Here is an Automator application to save each page of a PDF file as an image. You can do this with Preview, but it is tedious for documents with many pages.
Download “Save PDF Pages as Images.app” (219 KB; Mac OS X 10.5 required)
When you run the application, it begins by prompting you to select a PDF file. You can select any sort of file, but nothing much will happen if it’s not a PDF.
Next you can choose the output image format. 150 DPI PNG is the default format. I don’t think the compression setting applies to PNG images, but it does apply to JPEGs.
Rendering the images may take a moment. Then you’ll be asked to define how the output files should be named. I recommend the “Make Sequential” option. By default, page images from a three-page document will be named page-01.png
, page-02.png
, and page-03.png
.
Lastly, you can choose where to save the results. Choose “Other…” from the menu to select a folder that doesn’t appear among the default locations.
Now you have an image of each page in the PDF.
Posted on Tuesday, November 18th, 2008.
Pdftk 1.41 for Intel Macs
Pdftk is a useful utility for manipulating PDF files. A Macintosh binary of the current version was not available, except perhaps from Fink or Darwin Ports, so I built it myself. My version is not universal, but it doesn’t require a package manager, either.
Until such time as this binary is available directly from the official pdftk site, you can get it here:
Download pdftk 1.41 for Intel Macs 1MB
Note: the default pdftk Makefile settings result in a binary that still relies on gcj. Until such time as this issue is resolved, the binary probably won’t be much use!
Building pdftk
requires gcj
, which comes with gcc
, but apparently not with Mac OS X. So, I downloaded and built GCC 4.2.2. Why 4.2.2? Because it was the most recent version.
./configure --prefix=/usr/local/gcc/4.2.2 --disable-multilib
make
make install
The --prefix
option installs everything out of the way in its own little directory; I wasn’t really interested in upgrading to a new version of gcc
just to build pdftk
. The --disable-multilib
option turns off some crap that caused build errors.
Once that’s done, building pdftk
is just a matter of pointing the makefile at the new gcc
stuff.
cd pdftk
# In Makefile.MacOSX, define TOOLPATH=/usr/local/gcc/4.2.2/bin/
make -f Makefile.MacOSX
make install
So that’s how you roll your own.
Posted on Monday, November 26th, 2007.
strpdf
strpdf
creates single-page PDF files populated with one-line text strings. The page size and string placement are configured with command line options. It is a purposely simple tool.
Download
Installation instructions and other notes are included with the downloads.
- strpdf-1.0-mac.zip (1.9M) Requires Mac OS X 10.4; untested on Mac OS X 10.5.
- strpdf-1.0-win.zip (640K) Untested, but might work at the Windows command prompt.
- strpdf-1.0-kit.zip (95K) Requires a Tclkit for your platform (8.4.16 recommended).
Usage
Strings are placed on the page with the -text
option. General configuration options must be given before the first -text
option. PDF data is printed to stdout
, so redirection should be used to capture the result.
Here is a simple example:
strpdf -text 'Hello, world!' center middle > helloworld.pdf
The -text
option has three parameters. The first is the string to print. The second and third specify the horizontal and vertical locations of the string on the page, respectively. Valid horizontal positions are left
, center
, and right
. Valid vertical positions are top
, middle
, and bottom
. The left
, right
, top
, and bottom
positions must each be followed by an additional parameter which specifies the distance from the indicated edge of the page to the closest side of the string.
Multiple instances of the -text
option can be used to place multiple strings on the page:
strpdf -text 'Upper right' right 0.5 top 0.5 -text 'Lower left' left 0.5 bottom 0.5 > corners.pdf
The default page size is 8.5 × 11 inches (letter
). The -paper
option understands a few other common paper sizes, which can be listed with strpdf paper
:
strpdf -paper a4 -text 'A4 FTW' center top 1 > a4.pdf
Alternatively, arbitrary page dimensions can be specified with the -width
and -height
options:
strpdf -width 5 -height 5 -text 'Square' center middle > square.pdf
By default, page dimensions and string position parameters are interpreted as inches. The -units
option allows these values to be given in millimeters or points. The supported -units
parameters are mm
, pt
, and in
.
The -orient
option provides a landscape mode that swaps the width and height of the page. This can be done manually with the -width
and -height
options, but the landscape option is convenient for use with preset paper sizes:
strpdf -paper legal -orient landscape -text 'Legal fine print' center bottom 0.5 > landscape.pdf
The default font is 12-point Helvetica. The -size
option sets the font size (in points) and the -font
option sets the font face. If given before the first -text
string, these options set the default font. Given after the parameters of a particular -text
option, they modify only that string:
strpdf -font Times-Roman -size 18 -text 'One' left 1 top 1 -text 'Two' center top 1 -size 24 -font Courier -text 'Three' right 1 top 1 > fonts.pdf
Valid font faces can be listed with strpdf font
. Valid fonts are not necessarily available on your computer, nor are the fonts on your computer necessarily compatible with strpdf
.
There is a -compress
option which will compress the PDF data if given the
parameter 1
, but in most cases it yields little benefit. For small files such
as the examples on this page, compression may actually result in slightly larger files.
Applications
I use strpdf
in conjunction with pdftk
to “stamp” otherwise static PDF documents with bits of variable text. Because these are both free command line utilities, the process is easily automated and requires no commercial software. Here a registration string is stamped on each page of a report:
strpdf -text 'Registered to John Doe' center top 0.25 > registration.pdf pdftk document.pdf stamp registration.pdf output registered-document.pdf
Alternatively, strpdf
’s output can be piped directly to pdftk
:
strpdf -text 'Registered to John Doe' center top 0.25 | pdftk document.pdf stamp - output registered-document.pdf
Posted on Monday, November 26th, 2007.