Thursday, September 6, 2007

Printing Secrets Revealed: How to set Custom Page Sizes with CUPS Printjobs

So you have one of those sophisticated office printer models with adjustable guides that allow you to use any weird media size (with some sensible min/max value for width and height)? And you don't know how to tell CUPS to use that size when printing? (Ah... you don't have such a printer, and you are about to skip this article? Wait. The content may still be useful to you. See the last paragraph.)

Easy. Try one of these commands then:

 lp -d printername -o PageSize=Custom.4x6in \
-o fitplot /path/to/PDF ; # inches

lp -d printername -o PageSize=Custom.4x8cm \
-o fitplot /path/to/PDF ; # cm

lp -d printername -o PageSize=Custom.440x310 \
-o fitplot /path/to/PDF ; # points (1/72 of an inch)

These assume a few things:
  • you indeed have a printer named "printername" (how weird is this?!)
  • you want to print a PDF file
  • you want to make the printout fit onto the medium ("fitplot")
The "fit onto the medium" will happen automatically. CUPS will scale the page image up or down to the size that makes you PDF fit onto the sheet. It will also automatically rotate a page, if that makes it fit better into the available space.

This works also if you print other file types. And it even allows you to use fractions of an inch or cm units:
 lp -d printername -o PageSize=Custom.5.5x6.9in \
/path/to/ASCII.txt ;

lp -d printername -o PageSize=Custom.5x8.2cm \
-o fitplot /path/to/Photo.jpg ;

lp -d printername -o PageSize=Custom.440x310 \
-o fitplot /path/to/Scanned.tif ;

Supported image formats for CUPS printing are all of the commonly know, plus some more obscure ones: JPEG, TIFF (but not multipage TIFF!), PNG, GIF, PNM, PPM, SUN Raster, .... When the CUPS scheduler receives a printfile, it applies its "auto-typing" mechanism against it to find out its file format ("MIME type").

The received job format is then converted by an appropriate filter into a different one to make it better suited for further processing. (Overall, there may not only be one filter, but a whole chain of different ones which form a pipeline until the job is in a format that can be consumed by the target printer.)

With image and graphic formats, the first filter in the chain typically is "imagetops" or "imagetoraster". Both these filters understand the "fitplot" parameter that you gave on the above commandline, and act accordingly while converting their input into PS (PostScript) or CUPS Raster format.

You did notice that the "fitplot" parameter was skipped in the printing of the text, yes? Well, it does not make much sense here. Instead, to customize the size of your printed text you can specify "cpi" (characters per inch) and "lpi", as well as top, bottom, left and/or right margins:
 lp -d printername \
-o PageSize=Custom.10x12cm /path/to/ASCII.txt \
-o page-top=33 \
-o page-bottom=44 \
-o page-left=60 \
-o page-right=80 \
-o lpi=5.53 \
-o cpi=11.3 \

So you think this "custom page size" tip isn't of much use for you? Hold on. You can use it to "print to file" and generate PostScript pages that do have appropriate BoundingBoxes for leaflets /brochures you are going to hand to a commercial printshop for transfer onto paper. Or you can further process said PostScript into a polished PDF presentation that fits exactly on the wide screen of your shiny new notebook. (You don't know how to "print to file"? You don't know how to convert a PostScript to PDF? I'll deal with questions like these in one of the next blog entries. So come back, if you are interested.) Tell me your own use case for the CUPS custom page size print option...


greenleaf07 said...

Wow. This is great info and you're just getting started. I can't wait to learn more!

Anonymous said...

Superb info!

Just what I was looking for, spoon fed to me and my little /dev/brain :-)

Thanks a lot.

Bumper Sticker Printing said...

Superest Info!
I use it ungently.thank you very much.

Great net said...

Dear Writer, I bookmark your Blog For Reading I really love your Blog Post Please Keep update Reguraly.

I m From Online printing company

mark33sv said...

Hi, txs 4 explanetion

I have a ubuntu 9.10 distro
Bu i've tried to add PageSize to mi printer epson lx300
but in comand line, i culdn't
how ca i do it better?
so, but what is different way if i have this printer sharing on pcwin?

Boxes Printing said...

Really nice information thanks for share it.

3d ultrasounds said...

Interesting post. I have been wondering about this issue,so thanks for posting.

reversal of tubal ligation said...

Brilliant post and useful information…I think this is what I read somewhere…but I don’t know with your experience

printing london said...

Great information sharing with us. Thanks for it.

thermal bags said...

Thank you very much for that extraordinarily first class editorial! Very creative, one of the nicer sites I have seen today. Keep up the great work.

Organic Supplements said...

I believe that natural and organic sources of vitamins and minerals are the best in comparison of any other packaged and plastic products. Always try to grow the stuff you need at your home. It is not only going to be cheaper but it will be a lot more beneficial for your health and your loved ones

Free Classified Ads said...

For this motive to provide every product to the customer, and to accomplish the all needs of the people we introduce an authentic and valuable E-marketing place where mushroom of beautiful and well equipped houses and accommodations are provided by the so worthy and trusty E-marketing place which is .

3d ultrasounds said...

Well described in above article.
It’s very informative and impressive.
Thanks for your update.

website design perth said...

Many people will take advantage of this credit. This will also give us a clearer picture of the housing market, as there will be no special incentive to buy after the credit is no longer offered.

Lingerie said...

Thanks for sharing this great article! I feel strongly about it and love learning more on this topic. It is extremely helpful for me. I hope you post again soon

Copyright UK said...

This post is a winner! Love the tips and everything you suggest..

emergency locksmith said...

Thanks for the information. I’m really glad that you share your ideas about this. I must relay this ideas to my friends.

organic supplements said...

Thanks for putting this together! This is obviously one great post.

Best Article Websites said...

Your blog post is very unique and well research, Thanks for your research on academic knowledge.
Advertising agencies in Karachi | Advertising agencies in Pakistan

Custom Tumblers said...

I honestly don't even know how much I spent for everything anymore. If I had to guess, it was probably about $4 a cup. I bought big sheets of vinyl at a local sign shop and only needed one!

AzM MzA said...

i use :: arch linux
epson tm-t20ii
using wine for a simple 32bit exe dotnet 4.0 ie8
need to custom fit a page size
created and installed package myself not in aur.
i can print from the exe software but even after i set custom page size via web gui it still reverts back to a standard format.
would the best solution be editing the ppd file to contain ONLY the page size i want?