alex_lazarev
alex_lazarev

Reputation: 39

Google cloud print. how to submit valid capabilities?

When i sending a printer job without capabilities, it's work and print:

<?php
$url = "http://www.google.com/cloudprint/submit?printerid=" . $printer_id . &output=json";
        $post = array(
            "printerid" => $printer_id,
            "capabilities" => '',
            "contentType" => "text/plain",
            "title" => $title,
            "content" => $docBytes
        );
        $post = http_build_query($post);
        $ret = $this->processRequest($url, $post, "");
?>

But now i need to print information in A7 format letter. So i wrote this code with some capabilities:

<?php
 $url = "http://www.google.com/cloudprint/submit?printerid=" . $printer_id . "&output=json";
        $post = array(
            "printerid" => $printer_id,
            "capabilities" => array('psk:MediaSizeWidth' => '74000', 'psk:MediaSizeHeight' => '104700'), 
            "contentType" => "text/plain",
            "title" => $title,
            "content" => $docBytes
        );

        $post = http_build_query($post);
        $ret = $this->processRequest($url, $post, "");
?>

And it's don't want to print. Just Error. Maybe someone know how to right way to do this?

Upvotes: 2

Views: 2957

Answers (2)

oldlol
oldlol

Reputation: 178

I'm currently implementing unattended printing for a web app using cloud print, and this has been a long day!

Everything worked fine when printing from the google dialog (https://www.google.com/cloudprint/gadget.html), but sending files through my API messed everything up (printing restaurant tickets on a thermal printer, ended up with a 50cm top margin)

After looking everywhere online, I realized the google print gadget is pure html, making the submit request very easy to capture. Just fire your developper tools, print something from the dialog, and check the "capabilities" value of the posted data.

The confusing part is that those settings need to be in a PPD-like format, not just a normal associative array.

You can print from the desired printer with the right settings, then copy the "capabilities" part as is in your API/whatever. As an exemple, here are mine:

{"capabilities":[{"name":"TmtPaperSource","type":"Feature","options":[{"ppd:value":"\"\"","name":"PageFeedCut","displayName":"Page [Feed, Cut]"}]},{"name":"TmtPaperReduction","type":"Feature","options":[{"ppd:value":"\"\"","name":"Both","displayName":"Top & Bottom margins"}]}]}

and formatted:

{
    "capabilities":[
        {
            "name":"TmtPaperSource",
            "type":"Feature",
            "options":[{
                "ppd:value":"\"\"",
                "name":"PageFeedCut",
                "displayName":"Page [Feed, Cut]"
            }]
        },
        {
            "name":"TmtPaperReduction",
            "type":"Feature",
            "options":[{
                "ppd:value":"\"\"",
                "name":"Both",
                "displayName":"Top & Bottom margins"
            }]
        }
    ]
}

Last note: you need to pass the WHOLE thing as the "capabilities" param, meaning your request is something like .../submit?capabilities={capabilities:[...]}, pretty confusing aswell!

Upvotes: 7

alex_lazarev
alex_lazarev

Reputation: 39

In GCP documentation i found, that capabilities(printing formats, copy count, etc.) supports only with Google Cloud Ready printers!

At this moment i found only one way to do that: just configure settings in your OS driver of printer at once to print in A7 and it will print always in A7

Upvotes: 0

Related Questions