'', "contentType" -6ren">
gpt4 book ai didi

php - 谷歌云打印。如何提交有效能力?

转载 作者:行者123 更新时间:2023-12-01 18:30:23 24 4
gpt4 key购买 nike

当我发送没有功能的打印机作业时,它可以工作并打印:

<?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, "");
?>

但现在我需要打印 A7 格式信函的信息。所以我编写了具有一些功能的代码:

<?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, "");
?>

而且它不想打印。只是错误。也许有人知道如何正确执行此操作?

最佳答案

我目前正在使用云打印为网络应用程序实现无人值守打印,这真是漫长的一天!

从 Google 对话框 ( https://www.google.com/cloudprint/gadget.html ) 打印时一切正常,但通过我的 API 发送文件却搞砸了一切(在热敏打印机上打印餐厅门票,最终顶部边距为 50 厘米)

在网上到处查找后,我意识到谷歌打印小工具是纯html的,使得提交请求非常容易捕获。只需启动您的开发工具,从对话框中打印一些内容,然后检查所发布数据的“功能”值。

令人困惑的部分是这些设置需要采用类似 PPD 的格式,而不仅仅是普通的关联数组。

您可以使用正确的设置从所需的打印机进行打印,然后复制 API/其他内容中的“功能”部分。作为一个例子,这是我的:

{"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"}]}]}

并格式化:

{
"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"
}]
}
]
}

最后一点:您需要将整个内容作为“功能”参数传递,这意味着您的请求类似于 .../submit?capability={capability:[...]} ,也很困惑!

关于php - 谷歌云打印。如何提交有效能力?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12724201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com