User:Gnyers/BookletPrinting

Jump to: navigation, search

This HOWTO provides an overview of the necessary steps to create a virtual printer which will reformat the printed document into a booklet format. Since this appears as normal printer device, it will process input submitted by any program which is capable of printing using CUPS. All processed documents will be delivered to the user by e-mail in PDF format. The next step is to actually print this document by a (duplex capable) physical printer, and finally fold and staple the pages together to produce the booklet.


Situation

Why booklet printing?

Even with double sided prints there is a convenience problem when one wants to achieve a book-like reading experience. Though using a simple office stapler one can bind the pages together, the end result is not very convenient to handle: pages need to fold very near to the paper's edge, which just after a short while will cause earmarks or the cover pages to get torn off.

A printed booklet is much more appealing because it is more convenient to hold and read. The booklet is also more durable, since the staples are located on the center fold line of the sheet.

How to produce a booklet?

A booklet can be produced from every document by simply reordering the pages.

These figures illustrates the procedure of creating a booklet, where the printed sheets contain 2 pages of the original document. This will obviously shrink the pages to 71% of their original size, but will result in an easy to handle booklet.

Step 1: Add empty pages (if necessary)

For booklet printing the document is required to contain pages that is some multiple of 4. If this is not the case, in the 1st step the document needs to be extended by as many pages as necessary, though the added number of pages are limited to 1-3.

Suppose that the original document contains n pages, the number of pages that needs to be added (m) can be calculated with this formula:

m = ( INT(n/4) + 1) * 4

Booklet-step1.png

In this example the original document contained 9 pages, so in order to be able to print this document as a booklet, 3 more blank pages needs to be added.

Step 2: Re-order pages

Booklet-step2.png

Step 3: Print pages

In this step contains several stages, the pages will be

  • resized to 71% of their original size,
  • rotated 90 degrees,
  • grouped together by 2 and put on the same side of a sheet

Booklet-step3.png

As a result, the original document which was formatted for an A4 portrait sheet, will end up as an A5 booklet. With a small modification of this process, it is also possible to retain the original size (A4 portrait) and end up with an A4 booklet. For this result the current step should only group 2 pages together and put them on an A3 sheet.

Result

After printing the document from the previous step on a duplex-capable printer, the printed sheets will contain the original document in the following layout.

Booklet-step4.png

Procedure

Required software

The procedure described in this document requires the following software to be installed:

  • cups
  • ghostscript-library
  • psutils
    • This package contains a number of utilities to manipulate Postscript files. For the purpose of booklet printing, the script below will use psbook and psnup
  • mailx

Create a virtual printer in CUPS

Add this printer definition to /etc/cups/printers.conf

   <Printer email_as_booklet>
   Info Generic with driver with driver Generic postscript printer
   DeviceURI pipe://usr/local/bin/email_as_booklet
   State Idle
   StateTime 1283866571
   Accepting Yes
   Shared Yes
   JobSheets none none
   QuotaPeriod 0
   PageLimit 0
   KLimit 0
   OpPolicy default
   ErrorPolicy stop-printer
   Option page-bottom 0
   Option page-right 0
   Option page-left 0
   Option page-top 0
   Option sides two-sided-short-edge
   </Printer>

Backend processing script

This fairly basic script provides an example for the backend processing script. In the above example the location of this script is /usr/local/bin/email_as_booklet

   #!/bin/bash
   
   ## Hard-coded domain name of the recepient
   # DOMAIN="@opensuse.org"
   # DOMAIN="@localhost"
   
   ## Let the local mailer daemon figure out the domain name
   DOMAIN=""
   
   ## Send all prints to this specific user
   #RECEPIENT=joe
   
   ## send the mail to the provided by CUPS, this user has submitted the job
   RECEPIENT="$PIPE_BACKEND_ARGV2"
   
   MSGTEXT="Dear $RECEPIENT,
   
   This is the automated CUPS booklet printing facility. 
   
   Please find in the attachment your print formatted as a book.
   
   Regards,
   CUPS
   "
   
   # ========= Don't touch the script below this line, =============
   # =========   unless you know what you're doing     =============
   TMP=/tmp
   OUTPUTTMP=$TMP/$$.ps
   OUTPUTPS=$TMP/$$.booklet.ps
   OUTPUTPDF=$TMP/$$.booklet.pdf
   
   
   LOG=$TMP/$$.log
   echo "Command line: \"$@\"" >> $LOG
   env >> $LOG
   
   # The print job is expected on the STDIN as Postscript
   cat - > "$OUTPUTTMP"
   # Reorder the pages for booklet layout, resize and put 2 pages on 1 sheet
   psbook "$OUTPUTTMP" | psnup -d -2 -c > "$OUTPUTPS"
   # convert the format Postscript to PDF
   ps2pdf "$OUTPUTPS" "$OUTPUTPDF"
   
   # for f in "$OUTPUTPDF" "$OUTPUTPS" "$LOG"
   for f in "$OUTPUTPDF" "$LOG"
   do
   	[ -f "$f" ] && ATTACHMENTS="$ATTACHMENTS -a $f"
   done
   
   mailx \
   	$ATTACHMENTS \
   	-s "CUPS booklet printer: job $PIPE_BACKEND_ARGV1 by $PIPE_BACKEND_ARGV2: $PIPE_BACKEND_ARGV3" \
   	${RECEPIENT}${DOMAIN} <<EOF
   $MSGTEXT
   EOF
   
   # Tidy up a bit
   rm "$OUTPUTPS" "$OUTPUTTMP" "$OUTPUTPDF" "$LOG"

Mail daemon configuration

To deliver the print the above script depends on the username provided by CUPS. The mailer daemon (Postfix, Sendmail, qmail etc...) must be configured such, that it will be able to figure out the recipient address based on this username. In relatively simple cases, like printing to a local virtual printer, should not be a problem. For more complex scenario's additional scripts might be necessary or specific configuration of the mail daemon. If for example, instead of delivering locally the mails need to be sent to another mailbox (e.g. a mailbox at an ISP or a corporate account) the local MTA needs to be configured for remote delivery, by either setting a relay host or configuring up full Internet delivery capabilities.

Printer driver

This is the Generic Postrscript printer driver provided by CUPS. The location of this file is /etc/cups/ppd/email_as_booklet.ppd

   *PPD-Adobe: "4.3"
   *%
   *% For information on using this, and to obtain the required backend
   *% script, consult http://www.openprinting.org/
   *%
   *% This file is published under the GNU General Public License
   *%
   *% PPD-O-MATIC (3.0.0 or newer) generated this PPD file. It is for use with 
   *% all programs and environments which use PPD files for dealing with
   *% printer capability information. The printer must be configured with the
   *% "foomatic-rip" backend filter script of Foomatic 3.0.0 or newer. This 
   *% file and "foomatic-rip" work together to support PPD-controlled printer
   *% driver option access with arbitrary free software printer drivers and
   *% printing spoolers.
   *%
   *% To save this file on your disk, wait until the download has completed
   *% (the animation of the browser logo must stop) and then use the
   *% "Save as..." command in the "File" menu of your browser or in the 
   *% pop-up manu when you click on this document with the right mouse button.
   *% DO NOT cut and paste this file into an editor with your mouse. This can
   *% introduce additional line breaks which lead to unexpected results.
   *%
   *% You may save this file as 'Generic-PostScript_Printer-Postscript.ppd'
   *%
   *%
   *FormatVersion:	"4.3"
   *FileVersion:	"1.1"
   *LanguageVersion: English 
   *LanguageEncoding: ISOLatin1
   *PCFileName:	"POSTSCRI.PPD"
   *Manufacturer:	"Generic"
   *Product:	"(PostScript Printer)"
   *cupsVersion:	1.0
   *cupsManualCopies: True
   *cupsModelNumber:  2
   *cupsFilter:	"application/vnd.cups-postscript 0 foomatic-rip"
   *%pprRIP:        foomatic-rip other
   *ModelName:     "Generic PostScript Printer"
   *ShortNickName: "Generic PS Printer"
   *NickName:      "Generic PostScript Printer Foomatic/Postscript"
   *PSVersion:	"(3010.000) 550"
   *PSVersion:	"(3010.000) 651"
   *PSVersion:	"(3010.000) 652"
   *PSVersion:	"(3010.000) 653"
   *PSVersion:	"(3010.000) 704"
   *PSVersion:	"(3010.000) 705"
   *PSVersion:	"(3010.000) 800"
   *LanguageLevel:	"3"
   *ColorDevice:	True
   *DefaultColorSpace: RGB
   *FileSystem:	False
   *Throughput:	"1"
   *LandscapeOrientation: Plus90
   *TTRasterizer:	Type42
   *1284DeviceID: "DRV:DPostscript,R1,M0,TP;"
   
   *driverName Postscript/Postscript: ""
   *driverType P/PostScript: ""
   *driverUrl: "http://partners.adobe.com/public/developer/ps/index_specs.html"
   *driverObsolete: False
   
   *VariablePaperSize: True
   
   *FoomaticIDs: Generic-PostScript_Printer Postscript
   *FoomaticRIPCommandLine: "cat%A%B%Z"
   *FoomaticRIPNoPageAccounting: True
   
   *OpenGroup: General/General
   
   *OpenUI *PageSize/Page Size: PickOne
   *OrderDependency: 100 AnySetup *PageSize
   *DefaultPageSize: A4
   *PageSize A4/A4: "<</PageSize[595 842]/ImagingBBox null>>setpagedevice"
   *PageSize Letter/US Letter: "<</PageSize[612 792]/ImagingBBox null>>setpagedevice"
   *PageSize 11x17/11x17: "<</PageSize[792 1224]/ImagingBBox null>>setpagedevice"
   *PageSize A3/A3: "<</PageSize[842 1191]/ImagingBBox null>>setpagedevice"
   *PageSize A5/A5: "<</PageSize[421 595]/ImagingBBox null>>setpagedevice"
   *PageSize B5/B5 (JIS): "<</PageSize[516 729]/ImagingBBox null>>setpagedevice"
   *PageSize Env10/Envelope #10: "<</PageSize[297 684]/ImagingBBox null>>setpagedevice"
   *PageSize EnvC5/Envelope C5: "<</PageSize[459 649]/ImagingBBox null>>setpagedevice"
   *PageSize EnvDL/Envelope DL: "<</PageSize[312 624]/ImagingBBox null>>setpagedevice"
   *PageSize EnvISOB5/Envelope B5: "<</PageSize[499 709]/ImagingBBox null>>setpagedevice"
   *PageSize EnvMonarch/Envelope Monarch: "<</PageSize[279 540]/ImagingBBox null>>setpagedevice"
   *PageSize Executive/Executive: "<</PageSize[522 756]/ImagingBBox null>>setpagedevice"
   *PageSize Legal/US Legal: "<</PageSize[612 1008]/ImagingBBox null>>setpagedevice"
   *CloseUI: *PageSize
   
   *OpenUI *PageRegion: PickOne
   *OrderDependency: 100 AnySetup *PageRegion
   *DefaultPageRegion: A4
   *PageRegion A4/A4: "<</PageSize[595 842]/ImagingBBox null>>setpagedevice"
   *PageRegion Letter/US Letter: "<</PageSize[612 792]/ImagingBBox null>>setpagedevice"
   *PageRegion 11x17/11x17: "<</PageSize[792 1224]/ImagingBBox null>>setpagedevice"
   *PageRegion A3/A3: "<</PageSize[842 1191]/ImagingBBox null>>setpagedevice"
   *PageRegion A5/A5: "<</PageSize[421 595]/ImagingBBox null>>setpagedevice"
   *PageRegion B5/B5 (JIS): "<</PageSize[516 729]/ImagingBBox null>>setpagedevice"
   *PageRegion Env10/Envelope #10: "<</PageSize[297 684]/ImagingBBox null>>setpagedevice"
   *PageRegion EnvC5/Envelope C5: "<</PageSize[459 649]/ImagingBBox null>>setpagedevice"
   *PageRegion EnvDL/Envelope DL: "<</PageSize[312 624]/ImagingBBox null>>setpagedevice"
   *PageRegion EnvISOB5/Envelope B5: "<</PageSize[499 709]/ImagingBBox null>>setpagedevice"
   *PageRegion EnvMonarch/Envelope Monarch: "<</PageSize[279 540]/ImagingBBox null>>setpagedevice"
   *PageRegion Executive/Executive: "<</PageSize[522 756]/ImagingBBox null>>setpagedevice"
   *PageRegion Legal/US Legal: "<</PageSize[612 1008]/ImagingBBox null>>setpagedevice"
   *CloseUI: *PageRegion
   
   *DefaultImageableArea: A4
   *ImageableArea A4/A4: "18 36 577 806"
   *ImageableArea Letter/US Letter: "18 36 594 756"
   *ImageableArea 11x17/11x17: "18 36 774 1188"
   *ImageableArea A3/A3: "18 36 824 1155"
   *ImageableArea A5/A5: "18 36 403 559"
   *ImageableArea B5/B5 (JIS): "18 36 498 693"
   *ImageableArea Env10/Envelope #10: "18 36 279 648"
   *ImageableArea EnvC5/Envelope C5: "18 36 441 613"
   *ImageableArea EnvDL/Envelope DL: "18 36 294 588"
   *ImageableArea EnvISOB5/Envelope B5: "18 36 481 673"
   *ImageableArea EnvMonarch/Envelope Monarch: "18 36 261 504"
   *ImageableArea Executive/Executive: "18 36 504 720"
   *ImageableArea Legal/US Legal: "18 36 594 972"
   
   *DefaultPaperDimension: A4
   *PaperDimension A4/A4: "595 842"
   *PaperDimension Letter/US Letter: "612 792"
   *PaperDimension 11x17/11x17: "792 1224"
   *PaperDimension A3/A3: "842 1191"
   *PaperDimension A5/A5: "421 595"
   *PaperDimension B5/B5 (JIS): "516 729"
   *PaperDimension Env10/Envelope #10: "297 684"
   *PaperDimension EnvC5/Envelope C5: "459 649"
   *PaperDimension EnvDL/Envelope DL: "312 624"
   *PaperDimension EnvISOB5/Envelope B5: "499 709"
   *PaperDimension EnvMonarch/Envelope Monarch: "279 540"
   *PaperDimension Executive/Executive: "522 756"
   *PaperDimension Legal/US Legal: "612 1008"
   
   *%*OpenUI *Resolution/Resolution: PickOne
   *%*OrderDependency: 110 AnySetup *Resolution
   *%*DefaultResolution: 300x300dpi
   *%*Resolution 150x150dpi/150 DPI: "<</HWResolution[150 150]>>setpagedevice"
   *%*Resolution 300x300dpi/300 DPI: "<</HWResolution[300 300]>>setpagedevice"
   *%*Resolution 600x600dpi/600 DPI: "<</HWResolution[600 600]>>setpagedevice"
   *%*Resolution 1200x600dpi/1200x600 DPI: "<</HWResolution[1200 600]>>setpagedevice"
   *%*Resolution 1200x1200dpi/1200 DPI: "<</HWResolution[1200 1200]>>setpagedevice"
   *%*Resolution 2400x600dpi/2400x600 DPI: "<</HWResolution[2400 600]>>setpagedevice"
   *%*Resolution 2400x1200dpi/2400x1200 DPI: "<</HWResolution[2400 1200]>>setpagedevice"
   *%*Resolution 2400x2400dpi/2400 DPI: "<</HWResolution[2400 2400]>>setpagedevice"
   *%*CloseUI: *Resolution
   
   *OpenUI *InputSlot/Media Source: PickOne
   *OrderDependency: 120 AnySetup *InputSlot
   *DefaultInputSlot: Default
   *InputSlot Default/Default: "<</ManualFeed false>>setpagedevice"
   *InputSlot Tray1/Tray 1: "<</ManualFeed false /MediaPosition 3>>setpagedevice"
   *InputSlot Tray2/Tray 2: "<</ManualFeed false /MediaPosition 0>>setpagedevice"
   *InputSlot Tray3/Tray 3: "<</ManualFeed false /MediaPosition 1>>setpagedevice"
   *InputSlot Manual/Manual Feeding: "<</ManualFeed true /MediaPosition 3>>setpagedevice"
   *CloseUI: *InputSlot
   
   *OpenUI *Duplex/Double-Sided Printing: PickOne
   *OrderDependency: 130 AnySetup *Duplex
   *DefaultDuplex: DuplexTumble
   *Duplex DuplexNoTumble/Long Edge (Standard): "<</Duplex true /Tumble false>>setpagedevice"
   *Duplex DuplexTumble/Short Edge (Flip): "<</Duplex true /Tumble true>>setpagedevice"
   *Duplex None/Off: "<</Duplex false>>setpagedevice"
   *CloseUI: *Duplex
   
   *CloseGroup: General
   
   *% Generic boilerplate PPD stuff as standard PostScript fonts and so on
   
   *DefaultFont: Courier
   *Font AvantGarde-Book: Standard "(001.006S)" Standard ROM
   *Font AvantGarde-BookOblique: Standard "(001.006S)" Standard ROM
   *Font AvantGarde-Demi: Standard "(001.007S)" Standard ROM
   *Font AvantGarde-DemiOblique: Standard "(001.007S)" Standard ROM
   *Font Bookman-Demi: Standard "(001.004S)" Standard ROM
   *Font Bookman-DemiItalic: Standard "(001.004S)" Standard ROM
   *Font Bookman-Light: Standard "(001.004S)" Standard ROM
   *Font Bookman-LightItalic: Standard "(001.004S)" Standard ROM
   *Font Courier: Standard "(002.004S)" Standard ROM
   *Font Courier-Bold: Standard "(002.004S)" Standard ROM
   *Font Courier-BoldOblique: Standard "(002.004S)" Standard ROM
   *Font Courier-Oblique: Standard "(002.004S)" Standard ROM
   *Font Helvetica: Standard "(001.006S)" Standard ROM
   *Font Helvetica-Bold: Standard "(001.007S)" Standard ROM
   *Font Helvetica-BoldOblique: Standard "(001.007S)" Standard ROM
   *Font Helvetica-Narrow: Standard "(001.006S)" Standard ROM
   *Font Helvetica-Narrow-Bold: Standard "(001.007S)" Standard ROM
   *Font Helvetica-Narrow-BoldOblique: Standard "(001.007S)" Standard ROM
   *Font Helvetica-Narrow-Oblique: Standard "(001.006S)" Standard ROM
   *Font Helvetica-Oblique: Standard "(001.006S)" Standard ROM
   *Font NewCenturySchlbk-Bold: Standard "(001.009S)" Standard ROM
   *Font NewCenturySchlbk-BoldItalic: Standard "(001.007S)" Standard ROM
   *Font NewCenturySchlbk-Italic: Standard "(001.006S)" Standard ROM
   *Font NewCenturySchlbk-Roman: Standard "(001.007S)" Standard ROM
   *Font Palatino-Bold: Standard "(001.005S)" Standard ROM
   *Font Palatino-BoldItalic: Standard "(001.005S)" Standard ROM
   *Font Palatino-Italic: Standard "(001.005S)" Standard ROM
   *Font Palatino-Roman: Standard "(001.005S)" Standard ROM
   *Font Symbol: Special "(001.007S)" Special ROM
   *Font Times-Bold: Standard "(001.007S)" Standard ROM
   *Font Times-BoldItalic: Standard "(001.009S)" Standard ROM
   *Font Times-Italic: Standard "(001.007S)" Standard ROM
   *Font Times-Roman: Standard "(001.007S)" Standard ROM
   *Font ZapfChancery-MediumItalic: Standard "(001.007S)" Standard ROM
   *Font ZapfDingbats: Special "(001.004S)" Standard ROM
   
   *%*ParamCustomPageSize Width:  1 points 255 612
   *%*ParamCustomPageSize Height: 2 points 396 1008
   *%*ParamCustomPageSize WidthOffset: 3 points 0 0
   *%*ParamCustomPageSize HeightOffset: 4 points 0 0
   
   *ParamCustomPageSize Orientation: 5 int 0 1

Steps to create a booklet print

Print the original document

The approach chosen by this document has the advantage that it is quite generic: any program that can print will be capable of producing booklets. It doesn't matter if it is a legacy program or the very latest version of OpenOffic.org, a web browser or a CAD application, end users will be able to produce booklets using the exact same procedure. If this virtual printer is shared using Samba, it is even possible to produce booklets from Windows programs.

Print the document using a suitable program to the virtual printer "email_as_booklet". Shortly after the submission of the print job the PDF should be delivered by e-mail.

Print the resulting booklet

Using any PDF reader, or simply CUPS' lp, submit the booklet PDF to a physical printer.

There are two important things to remember:

  • the printer must be capable of double sided printing, and
  • make sure that the binding edge is set to short

Fold and staple

For this step a stapler with a long arm is needed, which can reach to the middle of paper sheets. Depending on the amount of pages that needs to get stapled together the staper also need to be appropriately studry.

The finished booklet should look something like this

Booklet-step5.png


Links

[[en:SDB:Booklet Printing]] [[Category:SDB:Printing]]