This blog has moved! Redirecting...
You should be automatically redirected. If not, visit http://scrolls.mafgani.net/ and update your bookmarks.

Monday, July 31, 2006

Cropping a PDF Document

Easily accomplished using pdftops:


$ pdftops -paperw WIDTH -paperh HEIGHT -noshrink -expand document.pdf && ps2pdf document.ps


WIDTH and HEIGHT are in points -- they basically specify the dimensions of the image to be cropped.

Content is extracted from the center of the page. This technique is specially useful as a bypass for using psfrag with pdfLatex:


  • Save EPS figure with TAGS

  • Create a very simple tex document that simply includes the figure (centered) with psfrag replacements and run latex -> dvips -> ps2pdf

  • Follow the step above to crop out the figure.



The cropped out figure will have the TAGS replaced and be in PDF format -- ready to be used with pdfLatex!

UPDATE [16 July 2009] It looks like pdfcrop might actually be a better option:

$ pdfcrop --help
PDFCROP 1.5, 2004/06/24 - Copyright (c) 2002, 2004 by Heiko Oberdiek.
Syntax: pdfcrop [options] <input[.pdf]> [output file]
Function: Margins are calculated and removed for each page in the file.
Options: (defaults:)
--help print usage
--(no)verbose verbose printing (false)
--(no)debug debug informations (false)
--gscmd <name> call of ghostscript (gs)
--pdftexcmd <name> call of pdfTeX (pdftex)
--margins "<left> <top> <right> <bottom>" (0 0 0 0)
add extra margins, unit is bp. If only one number is
given, then it is used for all margins, in the case
of two numbers they are also used for right and bottom.
--(no)clip clipping support, if margins are set (false)
--(no)hires using `%%HiResBoundingBox' (false)
instead of `%%BoundingBox'
--papersize <foo> parameter for gs's -sPAPERSIZE=<foo>,
use only with older gs versions <7.32 ()
Examples:
pdfcrop --margins 10 input.pdf output.pdf
pdfcrop --margins '5 10 5 20' --clip input.pdf output.pdf


The tool comes as a part of the 'tetex' package.

Sunday, July 16, 2006

Finally, NTFS write support!

Slashdot ran a story yesterday about the new fully open source NTFS driver that has full read and write support for NTFS volumes. Although still in BETA phase it looks really promising. Too bad it doesn't work on 64-bit systems yet. I'm definitely keeping my eyes peeled for this one ..

More details and download links here:

[announcement] ntfs-3g: open source read-write driver

Creating directory hierarchies in bash

The BASH 'brace expansion' feature can be used to create whole directory trees using a single command. From the man page for BASH:


Brace Expansion
Brace expansion is a mechanism by which arbitrary strings may be gener‐
ated. This mechanism is similar to pathname expansion, but the file‐
names generated need not exist. Patterns to be brace expanded take the
form of an optional preamble, followed by either a series of comma-sep‐
arated strings or a sequence expression between a pair of braces, fol‐
lowed by an optional postscript. The preamble is prefixed to each
string contained within the braces, and the postscript is then appended
to each resulting string, expanding left to right.

Brace expansions may be nested. The results of each expanded string
are not sorted; left to right order is preserved. For example,
a{d,c,b}e expands into `ade ace abe'.

A sequence expression takes the form {x..y}, where x and y are either
integers or single characters. When integers are supplied, the expres‐
sion expands to each number between x and y, inclusive. When charac‐
ters are supplied, the expression expands to each character lexico‐
graphically between x and y, inclusive. Note that both x and y must be
of the same type.

Brace expansion is performed before any other expansions, and any char‐
acters special to other expansions are preserved in the result. It is
strictly textual. Bash does not apply any syntactic interpretation to
the context of the expansion or the text between the braces.

A correctly-formed brace expansion must contain unquoted opening and
closing braces, and at least one unquoted comma or a valid sequence
expression. Any incorrectly formed brace expansion is left unchanged.
A { or , may be quoted with a backslash to prevent its being considered
part of a brace expression. To avoid conflicts with parameter expan‐
sion, the string ${ is not considered eligible for brace expansion.

This construct is typically used as shorthand when the common prefix of
the strings to be generated is longer than in the above example:

mkdir /usr/local/src/bash/{old,new,dist,bugs}
or
chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}

Brace expansion introduces a slight incompatibility with historical
versions of sh. sh does not treat opening or closing braces specially
when they appear as part of a word, and preserves them in the output.
Bash removes braces from words as a consequence of brace expansion.
For example, a word entered to sh as file{1,2} appears identically in
the output. The same word is output as file1 file2 after expansion by
bash. If strict compatibility with sh is desired, start bash with the
+B option or disable brace expansion with the +B option to the set com‐
mand (see SHELL BUILTIN COMMANDS below).


So, for example:


$ mkdir -p root/{1/{1.1,1.2,1.3},2,3/{3.1,3.2/{3.2.1,3.2.2}}}

$ tree
.
`-- root
|-- 1
| |-- 1.1
| |-- 1.2
| `-- 1.3
|-- 2
`-- 3
|-- 3.1
`-- 3.2
|-- 3.2.1
`-- 3.2.2

11 directories, 0 files


The '-p' option to mkdir makes it create the parent directories if they do not exist.

Tuesday, July 11, 2006

Working with LaTeX & KPDF

KPDF is particularly handy in "watch file" mode. To activate, go to:

Settings -> Configure KPDF...

and check "Watch file" in the General section.

This causes KPDF to watch the file for changes and reload it automatically. Really handy when you don't want to keep navigating to the old page after an edit and reload ..