atans / atans-gcp
Zend Framework 2 的 Google Cloud Print 模块
v1
2014-04-24 09:45 UTC
Requires
- php: >=5.3.3
- zendframework/zendframework: ~2.1
This package is auto-updated.
Last update: 2024-09-13 23:19:52 UTC
README
Zend Framework 2 的 Google Cloud Print 模块(Beta 版本)
安装
使用 composer
1. 在您的 composer.json 文件中添加此项目
"require": {
"atans/atans-gcp": "dev-master"
}
2. 现在运行以下命令让 composer 下载 AtansGCP
$ php composer.phar update
安装后
- 在您的
application.config.php
文件中启用它。
<?php return array( 'modules' => array( // ... 'AtansGCP', ), // ... );
-
将
./vendor/atans/atans-gcp/config/attansgcp.global.php.dist
复制到./config/autoload/attansgcp.global.php
-
通过
Google Chrome
或https://www.google.com/cloudprint/learn/
将打印机添加到您的电子邮件账户 -
编辑
./config/autoload/attansgcp.global.php
'gcp_email' => 'your.email@gmail.com',
'gcp_password' => 'your.email.password',
使用它
获取打印机
class IndexController extends AbstractActionController { public function indexAction() { $cloudPrint = $this->getServiceLocator()->get('AtansGCP\Google\CloudPrint\CloudPrint'); $printers = $cloudPrintService->getPrinters(); var_dump($printers); } //...
提交作业
class IndexController extends AbstractActionController { public function indexAction() { $file = 'example.pdf'; $handle = fopen($file, 'r'); $content = fread($handle, filesize($file)); fclose($handle); $cloudPrintService = $this->getServiceLocator()->get('AtansGCP\Google\CloudPrint\CloudPrint'); // Your printer id $printerId = 'fb3a765e-50ad-94b0-6101-example'; // Set page size as A4 $mediaSizeTicket = new \AtansGCP\Google\CloudPrint\Ticket\Item\MediaSizeTicketItem(); $mediaSizeTicket->setVendorId('psk:ISOA4') ->setWidthMicrons(210000) ->setHeightMicrons(297000); $printTicket = new \AtansGCP\Google\CloudPrint\Ticket\Section\PrintTicketSection(); $printTicket->setMediaSize($mediaSizeTicket); $ticket = new \AtansGCP\Google\CloudPrint\Model\Ticket(); $ticket->setPrint($printTicket); $submit = new \AtansGCP\Google\CloudPrint\Model\Submit(); $submit->setTitle('Example') ->setContent($content) ->setTicket($ticket) ->setPrinterId($printerId) ->setContentType('application/pdf'); /** * @var \AtansGCP\Google\CloudPrint\Response\SubmitResponse $response */ $response = $this->getCloudPrintService()->submit($submit); var_dump($response->getSuccess()); var_dump($response->getJob()); } //...