infernobass7/laravel-print-node

此包最新版本(v0.1.1)没有提供许可证信息。

在 Laravel 中使用 PrintNode 打印。http://www.printnode.com

v0.1.1 2017-04-27 13:57 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:15:25 UTC


README

Laravel 对 PrintNode API 的包装器。更多关于 PrintNode 的信息可以在这里找到: http://www.printnode.com

Laravel 5

此包是用 Laravel 5.4 编写的,但应该支持 Laravel 5 的早期版本。

安装

您可以通过 Composer 拉取此包。

composer require infernobass7/laravel-print-node

您需要将以下行添加到 config/app.php

'providers' => [
    ...
    Infernobass7\PrintNode\PrintNodeServiceProvider::class,
    ...
]

接下来,您需要发布配置文件。

php artisan vendor:publish --provider="Infernobass7\PrintNode\PrintNodeServiceProvider"

#配置 配置文件自带两个部分。第一个是认证,这是包正常工作所必需的。用户名可以是 API 密钥或电子邮件地址。如果您使用 API 密钥,则不应提供密码。但是,如果您使用电子邮件地址,则必须提供密码。第二个部分是打印的配置选项。如果没有指定 PrintJob,则将使用这些选项作为默认值。

return [
    'auth' => [
        /*
         * Use this to set either API Key or email
         */
        'username' => '',
        
        /*
         * Do not set this if you are using API Key
         */
        'password' => ''
    ],
    
    'options' => [
        /*
         *  * = Options only available when installed client is running on a OSX Machine
         */
//      'bin' => , // String
//      'collate' => , // Boolean
//      'copies' => , // Integer
//      'dpi' => , // String
//      'duplex' => , // String - "long-edge" or "short-edge"
//      'fit_to_page' => , // * Boolean
//      'media' => , //String
//      'nup' => , // * String - Print Multiple Pages on One Sheet
//      'pages' => , // String - Specific Set of pages from the PDF. Format explained here https://printnode.com/docs/api/curl/#parameters
//      'paper' => , // String - Named paper size
//      'rotate' => // Integer - Rotate Page specified degrees ( accepted values: 90, 180, or 270 )
    ]
];

#用法

##打印机 此类处理从 PrintNode 获取打印机列表。

/*
 * Will return a collection of Printer Objects 
 */
Printer::all();
 
/*
 * Will return the specific printer Object based on the ID.
 * The ID can retrieved from PrintNode's service.
 */
$printer = Printer::get($printer_id);

/*
 * Retrieve a list of all PrintJobs previously printed on the Printer
 */
$previousJobs = $printer->getPrintJobs(); 
 
/*
 * Retrieve a specific print job previousl printed on the Printer
 */
$previousJob = $printer->getPrintJob($id);

##打印任务 此类处理获取和创建新的打印任务。

/*
 * Create a new PrintJob
 */
$job = new PrintJob($attributes = []);
 
/*
 * Sends the print job to the specified Printer
 */
$job->print(Printer $printer);
// Alternatively
$printer->print(PrintJob $job);

/*
 * Fluent Setters to create PrintJob
 */
 
/*
 * Grabs file based on the path of the storage disk defined in Storage Configuration 
 * Set contentType to either 'raw_base64' or 'pdf_base64'
 */
$job->setFile($path, $disk = 'local', $raw = false);

/*
 * Sets the content to the URI provided
 * Sets Credentials for basic Authentication type
 */
$job->setUri($uri, $credentials = null, $raw = false);
// Alternatively 
$job->setUri($uri)->setAuthentication($credentials, $basic = true);

/*
 * 
 */
$job->setOptions($options = []);

/*
 * Please note the next two methods are not the same.
 */

/*
 * Sets the number of times that the PrintJob is going to be sent to the Printer
 */
$job->setQuantity(int $qauntity);

/*
 * Sets the number of copies that are printed per PrintJob
 */
$job->setCopies(int $quantity);

/*
 * Sets the source name to display on PrintNode
 */
$job->setSource($name);

/*
 * Sets how long in seconds the PrintJob will sit in the queue waiting to be printed
 * Afterwards it will be deleted
 */
$job->setExpireAfter(int $seconds);