Posts Tagged ‘pdf’

Convert PDF to grayscale and compress

Friday, July 16th, 2010

Recently I compressed a 25 MB color pdf to a 900 KB grayscale pdf. Here’s how I did it:

  1. Open the original.pdf in Preview. Select File > Save As… and choose Quartz Filter: Gray Tone. Save it as original_gray.pdf. My 25 MB color image was reduced to 13 MB by this step alone.
    Note: You could do this in Acrobat but it’s much harder to find in the UI and actually crashed the program on my pdf.
  2. Open original_gray.pdf in Acrobat. Select File > Save As… and choose Format: Acrobat PDF Files, Optimized. Then click Settings.
    Make sure Images is selected on the left.
    Change the color Downsample: line to Bicubic Downsampling to 200 ppi for images above 300 ppi
    Change the color Compression: line to JPEG, High
    Change the grayscale Downsample: line to Bicubic Downsampling to 200 ppi for images above 300 ppi
    Change the grayscale Compression: line to JPEG, High

    Change the monochromatic Downsample: line to Bicubic Downsampling to 72 ppi for images above 108 ppi
    Change the monochromatic Compression: line to CCITT Group 4
    Note: You could do this in Preview with Quartz Filter: Reduce File Size, but some of images got their colors inverted.

Before
pdf compressed before
—> After
pdf compressed after

Change screenshot file format in Snow Leopard to PNG

Wednesday, June 16th, 2010

Just started working on a snow leopard machine and have been annoyed that the screenshots are saved as PDFs. To switch back to png I opened Terminal.app and issued this command:


defaults write com.apple.screencapture type png

Then you must issue:


killall SystemUIServer

to make the change take effect.

Note: You can replace png in the above with any of these: png, pdf, tiff, pict, bmp, gif, psd, sci, or tga.

source

Log in to nytimes.com download crossword puzzle and convert to pdf script

Tuesday, January 12th, 2010

I have given my girlfriend a subscription to the New York Times crossword puzzle which she (graciously?) allows me to use. Using the help of the decode_crossword.pl perl script, I have made a bash script to log in to nytimes.com, grab today’s puzzle in .puz format and convert it to pdf so I can easily print and view it. Here’s the script (replace userid and password with your own):


#!/bin/bash

if test -z $1 ; then
  date=`date +%b%d%y`
else
  date="$1"
fi

#
# log in to nytimes and save cookies
wget --post-data \
  "USERID=youremail%40gmail.com&PASSWORD=yourpassword&is_continue=true" \
  --save-cookies=cookies.txt --keep-session-cookies \
  -O /dev/null\
  http://www.nytimes.com/auth/login &>/dev/null

# download puzzle
wget --load-cookies=cookies.txt \
  http://select.nytimes.com/premium/xword/$date.puz &>/dev/null

# get rid of cookies
rm cookies.txt

# convert to pdf
./decode_crossword -P $date.puz | ps2pdf - $date.pdf &>/dev/null

# get rid of .puz version
rm $date.puz

Vi(m) tip #5: convert list of image files into latex figures

Wednesday, November 11th, 2009

If I select and copy (CMD+C) a bunch of image files in Finder
then paste (CMD+V) in TextEdit, then recopy and paste into vi(m), I can run the follow commands to make each file into a full blown latex figure. (Of course you can also just copy and paste the list using ls on any unix/linux machine.)

For eps files:


:%s/^\(.*eps\)$/\r\\begin{figure}[tbp]\r\\centering\r\\epsfig{file=\1,width=0.9\\linewidth,clip=}\r\\caption{}\r\\end{figure}/

and for others (png here, just replace with jpg etc.):


:%s/^\(.*png\)$/\r\\begin{figure}[tbp]\r\\centering\r\\includegraphics[width=0.9\\textwidth]{\1}\r\\caption{}\r\\end{figure}/

Example:

The first one-liner substitutes:


bilapl_all_bnds_ex.eps
bilapl_all_bnds_ey.eps
trilapl_all_bnds_ex.eps
trilapl_all_bnds_ey.eps
trilapl_all_bnds_ez.eps

with this:


\begin{figure}[tbp]
\centering
\epsfig{file=bilapl_all_bnds_ex.eps,width=0.9\linewidth,clip=}
\caption{}
\end{figure}

\begin{figure}[tbp]
\centering
\epsfig{file=bilapl_all_bnds_ey.eps,width=0.9\linewidth,clip=}
\caption{}
\end{figure}

\begin{figure}[tbp]
\centering
\epsfig{file=trilapl_all_bnds_ex.eps,width=0.9\linewidth,clip=}
\caption{}
\end{figure}

\begin{figure}[tbp]
\centering
\epsfig{file=trilapl_all_bnds_ey.eps,width=0.9\linewidth,clip=}
\caption{}
\end{figure}

\begin{figure}[tbp]
\centering
\epsfig{file=trilapl_all_bnds_ez.eps,width=0.9\linewidth,clip=}
\caption{}
\end{figure}