我目前正在向 php 后端系统添加功能以允许它直接打印,并且我正在尝试使用谷歌的云打印。将应用程序想象成一个在线购物车,我希望它打印拣货单(已完成的订单)而不需要有人登录。服务器是远程的,目的地有云就绪打印机。
到目前为止,只要我只是将 HTML、纯文本或 URL 传递给 PDF,我就已经成功地使用接口打印它。我可以将打印设置为彩色、无边距和打印质量。
但是,我遇到的问题是,系统创建的 PDF 不可公开访问,因此我无法将 URL 传递给文件,我需要传递文件的内容。
我一直在尝试修改我在网上找到的示例之一,但没有成功。但是我不懂这种语言,所以我很挣扎。
python HERE中的另一个例子我一直在尝试但没有成功!
我正在使用 PHP 和 Zend 框架来处理界面。这是我尝试过的一个示例,减少到我试图准备要发送的文件的位置,就像我说我不确定从 python 转换为 php,或者 python 脚本是否有效,但这就是我想出了:
<?php
// Test print a job:
$b64_pathname = PDF_PATH.'ec22c3.pdf'.'.b64';
$fileType = "application/pdf";
// Open the original file and base64 encode it:
$dataHandle = fopen(PDF_PATH.'ec22c3.pdf', "rb");
$dataContent = fread($dataHandle, filesize(PDF_PATH.'ec22ed167763a15e8591a3776f3c65c3.pdf'));
fclose($dataHandle);
$b64data = $fileType.base64_encode($dataContent);
// Store the base64 encoded file:
$ourFileHandle = fopen($b64_pathname, 'w');
fwrite($ourFileHandle, $b64data);
fclose($ourFileHandle);
// Read the contents of the base64 encoded file and delete it:
$fileHandle = fopen($b64_pathname, "rb");
$fileContent = fread($fileHandle, filesize($b64_pathname));
fclose($fileHandle);
unlink($b64_pathname);
// URL encode the file contents:
$file = urlencode($fileContent);
// Add the file and send to the printer:
$client->setParameterPost('content', $file);
$client->setParameterPost('contentType', $fileType);
$client->request(Zend_Http_Client::POST);
?>