This series is written by a representative of the latter group, which is comprised mostly of what might be called "productivity users" (perhaps "tinkerly productivity users?"). Though my lack of training precludes me from writing code or improving anyone else's, I can, nonetheless, try and figure out creative ways of utilizing open source programs. And again, because of my lack of expertise, though I may be capable of deploying open source programs in creative ways, my modest technical acumen hinders me from utilizing those programs in what may be the most optimal ways. The open-source character, then, of this series, consists in my presentation to the community of open source users and programmers of my own crude and halting attempts at accomplishing computing tasks, in the hope that those who are more knowledgeable than me can offer advice, alternatives, and corrections. The desired end result is the discovery, through a communal process, of optimal and/or alternate ways of accomplishing the sorts of tasks that I and other open source productivity users need to perform.
Showing posts with label psnup. Show all posts
Showing posts with label psnup. Show all posts

Sunday, March 27, 2016

Miscellaneous Monday quickies: manipulating and excising pages from pdfs

So you've gotten, via inter-library loan, the pdf's you requested to aid you in researching the article you're writing. For purposes of putting them on your e-reading device, the form they're in is probably perfectly suitable. But what if you'd like to do other things with one or more of them, such as printing them out? There is quite a range of pdf manipulation tools that can help you put them in a form more congenial to such aims.

One that I recently discovered, for example, allows you to "n-up" your pdf document, i. e., to put more than one page per sheet of paper. Should you wish to print the document, this can help you lessen paper waste. The utility is called pdfnup, and the relevant command for accomplishing this end is pdfnup --nup 2x2 myfile1.pdf myfile2.pdf. Presumably one could use 4x4 in place of 2x2 to get four pages per sheet instead of two.

This utility gives results similar to psnup, a utility I have used (and previously witten about in this blog) in the past for making booklets comprised of multiple pages per sheet of paper, though pdfnup likely lacks the advanced collating options of psnup. But psnup involves greater complexity in that it operates on postscript files, which usually need to be converted to or from some other format.

Getting back to the task at hand, should you wish to print out any of your pdf's with the aim of minimizing paper waste, you may well wish to eliminate extraneous pages from your document. In my experience, for example, inter-library loan pdf documents routinely include one or more copyright notice pages. Before printing such documents, I almost always try to exclude those pages--simple enough if you send them directly from the printer from a pdf reader. But what if you're taking the additional step of n-upping multiple pages per sheet?

As it turns out, pdfnup is actually part of a larger pdf-manipulation suite called pdfjam. And that suite enables you to not only n-up your pdf document, but to eliminate extraneous pages as part of the same process. To give an example, if you have a fifteen page document wherein the first and last pages are copyright notices that you wish to exclude from your 2-upp'ed version, you'd use the command

pdfjam MyDoc.pdf '2-14' --nup 2x1 --landscape --outfile MyDoc_2-up.pdf.

The meaning of the various command switches will, I think, be obvious.

This is just a thin slice of the capabilities offered by just one suite of pdf manipulating tools available under GNU/Linux. I have used other tools such as pdfedit, pdftk, flpsed, to good effect as well.

LATER EDIT: I just discovered a new and interesting functionality of pdfjam; it can convert pdf's from a4 to letter format (and vice versa). The relevant command is pdfjam --paper letter --outfile out.pdf in.pdf

Saturday, April 12, 2014

Miscellaneous Friday quickies: crop pdf margins with psnup

As sometimes happens, I recently needed to print off a portion of a public-domain work that's been scanned to portable document format and made available for download via Google Books. As the case proves to be at times, the original book had pages with fairly wide margins; when that sort of scanned book gets printed on letter-sized paper, you end up with a smallish text-box in the middle of a page that will have something like two-inch margins. That makes the text harder to read because the font ends up being relatively small, and it also results in waste of a lot of paper.

What to do, then, to make the text larger and make it occupy more of the page? I used three utilities for this job: xpdf to excise the target pages into a postscript file, psnup to enlarge the text and crop margins, and ps2pdf to convert the modified pages back to a pdf file. psnup is part of the psutils package, while ps2pdf relies on Ghostscript. A description of the steps I took follows.

With the pdf-viewer xpdf, the print dialog offer two option: print the document to a physical printer, or print to a postscript file. Both options allow for page-range stipulation. That's how I created a postscript file from the target pages.

Next, psnup--a really handy tool I've used previously for creating booklets (more about that in a future entry), but which I'd never considered might perform a job like this--was used to reduce margins, which had the added effect of increasing the text size. The command I used, which I appropriated from here, looks like this:

psnup -1 -b-200 infile.ps file_zoomed.ps

The crucial switch here seems to be -b (which is short for borders) followed by a negative numeral. Of course the numeral 200 as seen in this example will need to be modified to suit your circumstances.

The final step of converting file_zoomed.ps, using ps2pdf, to a pdf was simplest of all--in fact so simple that I won't even describe it here. I hope this brief description may be an aid to others wishing to execute a task like this.

Finally, I ran across some other related information of interest while reaserching how to crop pdf margins. Here, for example, is a page that describes a few other, more technically-involved ways to reduce margins: http://ma.juii.net/blog/scale-page-content-of-pdf-files. This posting on the Ubuntu forums has a really interesting script someone put together for making pdf booklets: http://ubuntuforums.org/showthread.php?t=1148764. And this one offers some clever tips on using another psutils utility--psbook--for making booklets: http://www.peppertop.com/blog/?p=35. Then, there's what might be the most straightforward utility of all for cropping pdf margins--pdfcrop. Since I could not get it to work for me in this instance, I looked for and found the alternative described above.

MUCH LATER EDIT: having done some further experimentation with pdfcrop I've discovered an important element: using negative values to specify width of margins. Doing this, I was able, using this tool, to trim margins to my staisfaction. A command such as pdfcrop --margins '-5 -25 -5 -40' MyDoc.pdf MyDoc-cropped.pdf ended up doing the trick for me quite nicely