2

Problems:

I am printing custom size scenes, the printing must work on a variety of printers, standard or with custom sizes, or roll-fed (particularly this). Some of the custom printers are edge-to-edge.

The user-defined canvas may or may not match the printer paper size.... If the image is smaller than the paper, some printers will center it, others (like HP) print it on top left.

On some printers I can set "Custom" paper, others do not support it.

If the printer has minimum margins, some printers seem to clip, others to render from the top-left margin, and ma or may not clip on image size.

I would like to handle the clipping and margins myself and send to the printer the image as it should fit on "page".


m_printer->setPaperSize(QPrinter::Custom);   //gives
QPrinter::setPaperSize: Illegal paper size 30

Assuming that the following works,

m_printer->setPaperSize(canvasRectangle.size(), QPrinter::Point);

getting the marked paper size in cups still returns the default marked in the ppd (Letter, w4h4, ...) (though I can print or cut that size)

What I need:

I need to find, for the (selected/custom) paper/page, the minimum margins.

I thought I could get the margins by just asking for them

qreal left, right, top, bottom;
m_printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Point);
qDebug() << left << right << top << bottom;

But regardless of printer (I tried HP, PDF and a custom edge-to-edge printer) I got 10 10 10 10.

I thought I would set them to 0 first... I got back 0. (but printing still used some tiny margins, which it either clipped or moved over depending on device, except for the edge-to-edge printers - so while I got no error setting margins to 0 when 0 is impossible, QPrinter told me it set margin to 0 successfully.)

Right now I am trying to make this work in Linux, using cups (and Qt 4.8) - I looked in the ppd of the various printers, but what I see, as ImageableArea for different provided sizes, is that each size has different margins - so that defies the minimum margins idea.

I imagined that the minimum margins (for maximum printable area) should not depend on the paper chosen, but on the printer geometry.

I considered getting the cups ppd option values for ImageableArea - but getting it for the "default" paper size doesn't seem useful if I am not using that paper size - and for custom paper size, there is a range so I don't know what I can get from it.

Also - I can't even seem able to get the cups option for ImageableArea:

const cups_dest_t* pDest = &m_pPrinters[iPrinterNumber];
for (int i = 0; i < pDest->num_options; ++i) 
    if (strcmp(pDest->options[i].name, pName) == 0) 
        // I can show options like "PageSize", "PageRegion" but not "ImageableArea"

I am struggling to understand this...

How can I find, using either Qt or cups, the minimum possible printer margins ?

Thalia
  • 13,637
  • 22
  • 96
  • 190
  • 1
    Unfortunately, different printer drivers do different things. PS printers should act sensibly per Postscript standards. But not all printers are natively postscript, and not all postscript-to-native conversions deal with margins and imageable area properly. It's a big mess. You'll have to deal with it on printer-to-printer basis, and your software will need a list of officially supported printers, and allow the user to override the imageable area/margins for their "unsupported" devices. It's like back in the DOS days when a text editor came with a list of printers it supported :( – Kuba hasn't forgotten Monica Oct 12 '16 at 17:44
  • Also note that custom page size code in PPD may require a PS interpreter; I'm not sure to what extent CUPS deals with that. When setting a custom page size, such PS code would compute e.g. the ImageableArea. You might want to refer to the [PPD spec](https://partners.adobe.com/public/developer/en/ps/5003.PPD_Spec_v4.3.pdf), have GhostScript handy, and expect lots of experimentation... – Kuba hasn't forgotten Monica Oct 12 '16 at 18:04

0 Answers0