inquid / yii2-inquid-google-print
使用Google Cloud Print服务打印文档和视图。
dev-master
2021-05-02 06:38 UTC
Requires
This package is auto-updated.
Last update: 2024-08-29 04:58:27 UTC
README
由于Google Cloud Print已被弃用,该项目将很快被归档,请关注PrintNode库,我们将其作为打印的替代方案。
Yii2 Google Cloud Print
使用Google Cloud Print服务打印文档和视图。
安装
通过composer安装此扩展是首选方式。
运行以下命令之一:
php composer.phar require --prefer-dist inquid/yii2-inquid-google-print "*"
或
"inquid/yii2-inquid-google-print": "*"
将以下内容添加到您的composer.json
文件的require部分。
配置
//Inquid Components
'GoogleCloudPrint' => [
'class' => 'inquid\googlecloudprint\GoogleCloudPrint',
'refresh_token' => '', // '' - if don't use refresh token offline, then this field must be empty
'client_id' => '...',
'client_secret' => '...',
'grant_type' => 'refresh_token',
'redirect_uri' =>'http://yourdomain.com/googlecloudauth', // http://yourdomain.com/?r=googlecloudauth
'default_printer_id' => '__google__docs'
],
//Inquid controllerMap
'controllerMap' => [
'googlecloudauth' => 'inquid\googlecloudprint\GooglecloudauthController',
],
用法
扩展安装后,只需在代码中通过以下方式使用即可:
/* Check Refresh Token */ Yii::$app->GoogleCloudPrint->checkRefreshTokenSession(Yii::$app->request->getAbsoluteUrl()); /* Get printers as an array */ $printers = Yii::$app->GoogleCloudPrint->getPrinters(); /* Render a GridView with the printers */ echo Yii::$app->GoogleCloudPrint->renderPrinters(); /* print html code */ //Yii::$app->GoogleCloudPrint->sendPrintToPrinterContent("__google__docs", "job3", "<b>boba</b>", "text/html"); /* If default printer is not sent, system will take the default printer in the configuration file */ //$result = Yii::$app->GoogleCloudPrint->sendPrintToPrinterContent("", "job3", "<b>boba</b>", "text/html"); /* Send pdf file to print */ $result = Yii::$app->GoogleCloudPrint->sendFileToPrinter("", "Simple pdf", Yii::getAlias('@vendor').'/inquid/yii2-inquid-google-print/simple.pdf', 'application/pdf'); /* Check if print works */ if (isset($result['status'])) { echo "it works!"; }
授权重定向URI
对于来自Web服务器的请求:http://yourdomain.com?r=googlecloudauth或漂亮的URL http://yourdomain.com/googlecloudauth/
注销链接
如果您使用在线令牌,可以通过以下URL注销:http://yourdomain.com?r=googlecloudauth/remove或漂亮的URL http://yourdomain.com/googlecloudauth/remove