Saturday, November 11, 2006

KPDF printing and margins

Up to now, KPDF did not let you specify the margins for printing, it always printed with 0 margins, today, seeing that from time to time there's a bug report with people asking about printing PDF with margins i started implementing it, i'm almost done, but have some problems understanding what a user wants when specifying margins.

Let's put a simple example. You have a single page A4 document that has a black rectangle drawn at 2cm of distance from each side. Now you choose to print it with 5cm margin on top. Which result should you get?

a) The printed sheet has the rectangle with these distances: bottom 1.66 cm, top 6.66 cm, left 2cm, right 2cm. That means the available height got reduced from 29,7cm to 24,7cm so distance of 2cm is now 1.66 in the vertical direction, but as available width did not change, you get aspect ratio lost.

b) The printed sheet has the rectangle with these distances: bottom 1.66 cm, top 6.66 cm, left 3.43cm, right 3.43cm. That means the available height got reduced from 29,7cm to 24,7cm so distance of 2cm is now 1.66 in the vertical direction, and to preserve aspect ratio, the available width got reduced from 21 to 17.465 cm, resulting in 1.66 + (21 - 17.465)/2 margin in left and right.

c) Something else

I don't really know what a user would expect when printing, as losing aspect ratio is always a bad idea, but case b) is quite confusing too as you get margins on the horizontal side when you only put it on the vertical side, ideas?


McEnroe said...

what about a checkbox called "keep aspect ratio" which lets the user decide what he wants?

Jean-Marc said...

Hi Albert and thanks a lot for taking care of that bug :)

As i stated in the report, the problem was when printing papers with very small margins, some text on the edge would not be printed. I also like to add margin notes, but sometimes the margins are too small for that.

Personally I have no use for very specific margins, I just need bigger margins and correct aspect ratio, so -> solution b.

Also, the UI should not be deceiving as is the case right now... If you're going to ajust the left/right/bottom margins automatically as in your example, please show it to the user so that he knows what's going on!


thrantastic said...

Thanks for getting to this bug!

The expected behavior for me would be to keep the same aspect ratio as in solution b. KGhostView seems to get it right as far as I can tell, so maybe you could see what that does?

Thanks again!

Daniel "Suslik" D. said...

I would second mcenroe's comment - make it a check box thing, but more in the tune of how Adobe Reader does it on Windows:

They have a "Scale and center to fit printer margins" check box in the printing dialog.

You can make that a box, activated by the "Scale to fit:" with the following options:
x Printer Margins
o Custom margins
[00] Upper
[00] Left [00] Right
[00] Lower

I cannot imagine a situations when I would want to loose the aspect ratio. You might as well go for "scale" all the time.

Anonymous said...

acroread has a very useful page preview in the printing dialog. I'd really love to see something like that in KPDF's (or KDE's) print dialog. Then you could implement both options, and the user could choose the one she wants. As a side effect, you won't get bug reports stating that your margin implementation behaves unexpectedly.

pipitas said...

I do not think you should implement it *that* way at all. Or not in the first step.

What it needs as a first stage, is roughly the feature set Acrobat provides for printing on Windows.

That means: What is really *much* *more* needed is to have a simple *scaling* feature, with a thumbnail preview (that approximately shows how the printed area relates/positions to the sheet of paper).

Combined with this we need support for the "fitplot" feature (or "scale to fit", as it is called on Windows). That means: fill the available space ("ImageableArea" keyword in the PPD) fully. CUPS supports "fitplot" for PDF printing, BTW.

ImageableArea is what is defined in the PPD as that aerea of the sheet that can be filled with ink or toner. Attempting to print beyond that, will result in a cropped image.

I'd expect fitplot (as well as scaling) to default to centering the image on the sheet, as well as automatically rotate it (if it needs to; like if you print A5sized, "landscale" document on an A4 sheet).

Please note, "fitplot" does not necessarily preserve aspect ratios. It is extremely useful for scaling a letter-sized document for printing on an A4 paper, for example; a very frequently occuring task in my office. (And in my experience, users do not really expect preservation of aspect ratios for this task -- they rather want to "fill the paper"; letter size has more width than A4, but has less height than A4).

If you indeed need preservation of aspect ratio, you can easily do it with "scaling=90%", or whatever....

Anonymous said...

When someone requests a margin that is will encroach on the printed page, I think the logical thing to do is crop the page accordingly.

So if they ask for a 5cm top margin crop 5cm down from the top edge of the paper. This will change the pages aspect ratio and it will print funny-looking but thats what they asked for.

I assume a revert is always available of course?!

Albert Astals Cid said...

@pipitas: Well, that is very interesting, but should be applied on kdeprint level, not on KPDF level and i really don't have time nor knowledge to do that :-/

nimatar said...

I would say b, negative values would be nice too (in case the .pdf has a very wide border for example)

pipitas said...


Why did you ask for input then in the first place?

Topic is "printing from kpdf". So both are involved: KDEPrint as well as kpdf. Which means we are discussing how the two are interfacing.

In any case: the application usually generates the print file and hands it over to KDEPrint (potentially, along with some "parameters"). So the application determines how that file is conditioned.

The kprinter dialog allows for custom print dialog extensions that can take user input specific to the application sending a file, or that determines what the application should put into the (PostScript) printfile.

For one example to look at, see the print dialog used by Kate (the editor). There are 3 additional tabs: "Text Settings", "Header & Footer", "Layout". Have a look.

With Kate, this kprinter extension lets the user determine frames, headers and footers, their colors and the strings contained.

I am told that creating such an extension is very easy.

Other applications which do their specific extensions to the kprinter dialog are: gwenview, khtml/konqueror, showfoto, digikam, kcron, kpresenter, kchart, kspread, kst, konsole, kig, kfax, kolf, kooka, kuickshow, umbrello, kview, kviewshell, khexedit, kwordquiz, kmplot.

What I propose is (I believe) relatively simple to implement, but covers 95% of needs when printing typical PDF documents (including the mentioned Letter <--> A4 size conversion/scaling). The CUPS support for "fitplot" (a.k.a. "scale to fit the paper size") uses all of the ImageableArea and may just be as simple the passing of the respective commandline parameter (and let CUPS do the job). [However, it would not work for cases where CUPS is not used.]

Most of the features you have been talking about clearly need to be applied at and belong to the application level (and *not* the KDEPrint level).

If you do not have time or knowledge... well, that is a different topic then.

However, it was *you* who started discussing the "interesting topic" of kpdf+printing, not me. :-)

Daniel "Suslik" D. said...

Just found a great centering / scaling box in Gwenview's print dialog... Stealing ready code will probably be easier.

Pierre Abbat said...

I get this message when printing business cards. What I want to happen is that the page prints in the exact size and position specified in the file, and anything that falls in the margin (which is a red stripe that extends beyond the cards) doesn't print.

What the two choices mean to me are:
Print with specified margins: the width is scaled to fit between the left and right margins, and the height is scaled to fit between the top and bottom margins, independently.
Print adapting margins to keep aspect ratio: the graphic area of the page is shrunk conformally to fit between the margins. Where it's put vertically (apparently it's infringing on the left and right margins) is not clear.
Neither is what I want.