mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-13 19:51:30 +00:00
cleanup & setting up sync update
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
; This file is for unifying the coding style for different editors and IDEs.
|
||||
; More information at http://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
@@ -1,21 +0,0 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2018
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -1,50 +0,0 @@
|
||||
{
|
||||
"name": "barryvdh/laravel-snappy",
|
||||
"description": "Snappy PDF/Image for Laravel",
|
||||
"keywords": ["laravel","snappy", "pdf", "image", "wkhtmltopdf", "wkhtmltoimage"],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Barry vd. Heuvel",
|
||||
"email": "barryvdh@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2",
|
||||
"illuminate/support": "^9|^10",
|
||||
"illuminate/filesystem": "^9|^10",
|
||||
"knplabs/knp-snappy": "^1.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"orchestra/testbench": "^7|^8"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Barryvdh\\Snappy\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Barryvdh\\Snappy\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Barryvdh\\Snappy\\ServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"PDF": "Barryvdh\\Snappy\\Facades\\SnappyPdf",
|
||||
"SnappyImage": "Barryvdh\\Snappy\\Facades\\SnappyImage"
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "phpunit"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Snappy PDF / Image Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option contains settings for PDF generation.
|
||||
|
|
||||
| Enabled:
|
||||
|
|
||||
| Whether to load PDF / Image generation.
|
||||
|
|
||||
| Binary:
|
||||
|
|
||||
| The file path of the wkhtmltopdf / wkhtmltoimage executable.
|
||||
|
|
||||
| Timout:
|
||||
|
|
||||
| The amount of time to wait (in seconds) before PDF / Image generation is stopped.
|
||||
| Setting this to false disables the timeout (unlimited processing time).
|
||||
|
|
||||
| Options:
|
||||
|
|
||||
| The wkhtmltopdf command options. These are passed directly to wkhtmltopdf.
|
||||
| See https://wkhtmltopdf.org/usage/wkhtmltopdf.txt for all options.
|
||||
|
|
||||
| Env:
|
||||
|
|
||||
| The environment variables to set while running the wkhtmltopdf process.
|
||||
|
|
||||
*/
|
||||
|
||||
'pdf' => [
|
||||
'enabled' => true,
|
||||
'binary' => env('WKHTML_PDF_BINARY', '/usr/local/bin/wkhtmltopdf'),
|
||||
'timeout' => false,
|
||||
'options' => [],
|
||||
'env' => [],
|
||||
],
|
||||
|
||||
'image' => [
|
||||
'enabled' => true,
|
||||
'binary' => env('WKHTML_IMG_BINARY', '/usr/local/bin/wkhtmltoimage'),
|
||||
'timeout' => false,
|
||||
'options' => [],
|
||||
'env' => [],
|
||||
],
|
||||
|
||||
];
|
||||
@@ -1,209 +0,0 @@
|
||||
## Snappy PDF/Image Wrapper for Laravel
|
||||
[](https://github.com/barryvdh/laravel-snappy/actions)
|
||||
[](http://choosealicense.com/licenses/mit/)
|
||||
[](https://packagist.org/packages/barryvdh/laravel-snappy)
|
||||
[](https://packagist.org/packages/barryvdh/laravel-snappy)
|
||||
[](https://fruitcake.nl/)
|
||||
|
||||
This package is a ServiceProvider for Snappy: [https://github.com/KnpLabs/snappy](https://github.com/KnpLabs/snappy).
|
||||
|
||||
### Wkhtmltopdf Installation
|
||||
|
||||
Choose one of the following options to install wkhtmltopdf/wkhtmltoimage.
|
||||
|
||||
1. Download wkhtmltopdf from [here](http://wkhtmltopdf.org/downloads.html);
|
||||
2. Or install as a composer dependency. See [wkhtmltopdf binary as composer dependencies](https://github.com/KnpLabs/snappy#wkhtmltopdf-binary-as-composer-dependencies) for more information.
|
||||
|
||||
#### Attention! Please note that some dependencies (libXrender for example) may not be present on your system and may require manual installation.
|
||||
|
||||
### Testing the wkhtmltopdf installation
|
||||
|
||||
After installing you should be able to run wkhtmltopdf from the command line / shell.
|
||||
|
||||
If you went for the second option the binaries will be at `/vendor/h4cc/wkhtmltoimage-amd64/bin` and `/vendor/h4cc/wkhtmltopdf-amd64/bin`.
|
||||
|
||||
#### Attention vagrant users!
|
||||
|
||||
Move the binaries to a path that is not in a synced folder, for example:
|
||||
|
||||
```bash
|
||||
cp vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64 /usr/local/bin/
|
||||
cp vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 /usr/local/bin/
|
||||
```
|
||||
|
||||
and make it executable:
|
||||
|
||||
```bash
|
||||
chmod +x /usr/local/bin/wkhtmltoimage-amd64
|
||||
chmod +x /usr/local/bin/wkhtmltopdf-amd64
|
||||
```
|
||||
|
||||
This will prevent the error 126.
|
||||
|
||||
### Package Installation
|
||||
|
||||
Require this package in your composer.json and update composer.
|
||||
|
||||
```bash
|
||||
composer require barryvdh/laravel-snappy
|
||||
```
|
||||
|
||||
### Laravel
|
||||
|
||||
**Laravel 5.5** uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider/Facade. If you also use laravel-dompdf, watch out for conflicts. It could be better to manually register the Facade.
|
||||
|
||||
After updating composer, add the ServiceProvider to the providers array in config/app.php
|
||||
|
||||
```php
|
||||
Barryvdh\Snappy\ServiceProvider::class,
|
||||
```
|
||||
|
||||
Optionally you can use the Facade for shorter code. Add this to your facades:
|
||||
|
||||
```php
|
||||
'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
|
||||
'SnappyImage' => Barryvdh\Snappy\Facades\SnappyImage::class,
|
||||
```
|
||||
|
||||
Finally you can publish the config file:
|
||||
|
||||
```bash
|
||||
php artisan vendor:publish --provider="Barryvdh\Snappy\ServiceProvider"
|
||||
```
|
||||
|
||||
### Snappy config file
|
||||
|
||||
The main change to this config file (config/snappy.php) will be the path to the binaries.
|
||||
|
||||
For example, when loaded with composer, the line should look like:
|
||||
|
||||
```php
|
||||
'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),
|
||||
```
|
||||
|
||||
If you followed the vagrant steps, the line should look like:
|
||||
|
||||
```php
|
||||
'binary' => '/usr/local/bin/wkhtmltopdf-amd64',
|
||||
```
|
||||
|
||||
For windows users you'll have to add double quotes to the bin path for wkhtmltopdf:
|
||||
|
||||
```php
|
||||
'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"'
|
||||
```
|
||||
|
||||
### Lumen
|
||||
In `bootstrap/app.php` add:
|
||||
|
||||
```php
|
||||
class_alias('Barryvdh\Snappy\Facades\SnappyPdf', 'PDF');
|
||||
$app->register(Barryvdh\Snappy\LumenServiceProvider::class);
|
||||
```
|
||||
|
||||
Optionally, add the facades like so:
|
||||
|
||||
```php
|
||||
class_alias(Barryvdh\Snappy\Facades\SnappyPdf::class, 'PDF');
|
||||
class_alias(Barryvdh\Snappy\Facades\SnappyImage::class, 'SnappyImage');
|
||||
```
|
||||
|
||||
To customise the configuration file, copy the file `/vendor/barryvdh/laravel-snappy/config/snappy.php` to the `/config` folder.
|
||||
|
||||
### Usage
|
||||
|
||||
You can create a new Snappy PDF/Image instance and load a HTML string, file or view name. You can save it to a file, or inline (show in browser) or download.
|
||||
|
||||
Using the App container:
|
||||
|
||||
```php
|
||||
$snappy = App::make('snappy.pdf');
|
||||
//To file
|
||||
$html = '<h1>Bill</h1><p>You owe me money, dude.</p>';
|
||||
$snappy->generateFromHtml($html, '/tmp/bill-123.pdf');
|
||||
$snappy->generate('http://www.github.com', '/tmp/github.pdf');
|
||||
//Or output:
|
||||
return new Response(
|
||||
$snappy->getOutputFromHtml($html),
|
||||
200,
|
||||
array(
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'attachment; filename="file.pdf"'
|
||||
)
|
||||
);
|
||||
```
|
||||
|
||||
Using the wrapper:
|
||||
|
||||
```php
|
||||
$pdf = App::make('snappy.pdf.wrapper');
|
||||
$pdf->loadHTML('<h1>Test</h1>');
|
||||
return $pdf->inline();
|
||||
```
|
||||
|
||||
Or use the facade:
|
||||
|
||||
```php
|
||||
$pdf = PDF::loadView('pdf.invoice', $data);
|
||||
return $pdf->download('invoice.pdf');
|
||||
```
|
||||
|
||||
You can chain the methods:
|
||||
|
||||
```php
|
||||
return PDF::loadFile('http://www.github.com')->inline('github.pdf');
|
||||
```
|
||||
|
||||
You can change the orientation and paper size
|
||||
|
||||
```php
|
||||
PDF::loadHTML($html)->setPaper('a4')->setOrientation('landscape')->setOption('margin-bottom', 0)->save('myfile.pdf')
|
||||
```
|
||||
|
||||
If you need the output as a string, you can get the rendered PDF with the output() function, so you can save/output it yourself.
|
||||
|
||||
See the [wkhtmltopdf manual](http://wkhtmltopdf.org/usage/wkhtmltopdf.txt) for more information/settings.
|
||||
|
||||
### Testing - PDF fake
|
||||
|
||||
As an alternative to mocking, you may use the `PDF` facade's `fake` method. When using fakes, assertions are made after the code under test is executed:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use PDF;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
public function testPrintOrderShipping()
|
||||
{
|
||||
PDF::fake();
|
||||
|
||||
// Perform order shipping...
|
||||
|
||||
PDF::assertViewIs('view-pdf-order-shipping');
|
||||
PDF::assertSee('Name');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Other available assertions:
|
||||
|
||||
```php
|
||||
PDF::assertViewIs($value);
|
||||
PDF::assertViewHas($key, $value = null);
|
||||
PDF::assertViewHasAll(array $bindings);
|
||||
PDF::assertViewMissing($key);
|
||||
PDF::assertSee($value);
|
||||
PDF::assertSeeText($value);
|
||||
PDF::assertDontSee($value);
|
||||
PDF::assertDontSeeText($value);
|
||||
PDF::assertFileNameIs($value);
|
||||
```
|
||||
|
||||
### License
|
||||
|
||||
This Snappy Wrapper for Laravel is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
namespace Barryvdh\Snappy\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade as BaseFacade;
|
||||
|
||||
class SnappyImage extends BaseFacade {
|
||||
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor() { return 'snappy.image.wrapper'; }
|
||||
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
namespace Barryvdh\Snappy\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade as BaseFacade;
|
||||
use Barryvdh\Snappy\PdfFaker;
|
||||
|
||||
|
||||
/**
|
||||
* @method static \Barryvdh\Snappy\PdfWrapper setPaper($paper, $orientation = 'portrait')
|
||||
* @method static \Barryvdh\Snappy\PdfWrapper setWarnings($warnings)
|
||||
* @method static \Barryvdh\Snappy\PdfWrapper setOptions(array $options)
|
||||
* @method static \Barryvdh\Snappy\PdfWrapper loadView($view, $data = array(), $mergeData = array(), $encoding = null)
|
||||
* @method static \Barryvdh\Snappy\PdfWrapper loadHTML($string, $encoding = null)
|
||||
* @method static \Barryvdh\Snappy\PdfWrapper loadFile($file)
|
||||
* @method static string output($options = [])
|
||||
* @method static \Barryvdh\Snappy\PdfWrapper save()
|
||||
* @method static \Illuminate\Http\Response download($filename = 'document.pdf')
|
||||
* @method static \Illuminate\Http\Response inline($filename = 'document.pdf')
|
||||
*
|
||||
*/
|
||||
class SnappyPdf extends BaseFacade {
|
||||
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor() { return 'snappy.pdf.wrapper'; }
|
||||
|
||||
/**
|
||||
* Replace the bound instance with a fake.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function fake()
|
||||
{
|
||||
static::swap(new PdfFaker(app('snappy.pdf')));
|
||||
}
|
||||
|
||||
}
|
||||
-104
@@ -1,104 +0,0 @@
|
||||
<?php namespace Barryvdh\Snappy;
|
||||
|
||||
use Knp\Snappy\Image;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class IlluminateSnappyImage extends Image {
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Filesystem\Filesystem
|
||||
* @param string $binary
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(Filesystem $fs, $binary, array $options, array $env)
|
||||
{
|
||||
parent::__construct($binary, $options, $env);
|
||||
|
||||
$this->fs = $fs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the "file_get_contents" function
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getFileContents($filename)
|
||||
{
|
||||
return $this->fs->get($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the "file_exists" function
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function fileExists($filename)
|
||||
{
|
||||
return $this->fs->exists($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the "is_file" method
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isFile($filename)
|
||||
{
|
||||
return $this->fs->isFile($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the "filesize" function
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return integer or FALSE on failure
|
||||
*/
|
||||
protected function filesize($filename)
|
||||
{
|
||||
return $this->fs->size($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the "unlink" function
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function unlink($filename)
|
||||
{
|
||||
return $this->fs->delete($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the "is_dir" function
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isDir($filename)
|
||||
{
|
||||
return $this->fs->isDirectory($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the mkdir function
|
||||
*
|
||||
* @param string $pathname
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function mkdir($pathname)
|
||||
{
|
||||
return $this->fs->makeDirectory($pathname, 0777, true, true);
|
||||
}
|
||||
|
||||
}
|
||||
-108
@@ -1,108 +0,0 @@
|
||||
<?php namespace Barryvdh\Snappy;
|
||||
|
||||
use Knp\Snappy\Pdf;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class IlluminateSnappyPdf extends Pdf {
|
||||
/**
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $fs;
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Filesystem\Filesystem
|
||||
* @param string $binary
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(Filesystem $fs, $binary, array $options, array $env)
|
||||
{
|
||||
parent::__construct($binary, $options, $env);
|
||||
|
||||
$this->fs = $fs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the "file_get_contents" function
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getFileContents($filename)
|
||||
{
|
||||
return $this->fs->get($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the "file_exists" function
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function fileExists($filename)
|
||||
{
|
||||
return $this->fs->exists($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the "is_file" method
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isFile($filename)
|
||||
{
|
||||
return strlen($filename) <= PHP_MAXPATHLEN && $this->fs->isFile($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the "filesize" function
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return integer or FALSE on failure
|
||||
*/
|
||||
protected function filesize($filename)
|
||||
{
|
||||
return $this->fs->size($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the "unlink" function
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function unlink($filename)
|
||||
{
|
||||
return $this->fs->delete($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the "is_dir" function
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isDir($filename)
|
||||
{
|
||||
return $this->fs->isDirectory($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the mkdir function
|
||||
*
|
||||
* @param string $pathname
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function mkdir($pathname)
|
||||
{
|
||||
return $this->fs->makeDirectory($pathname, 0777, true, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
<?php namespace Barryvdh\Snappy;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Knp\Snappy\Image as SnappyImage;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
/**
|
||||
* A Laravel wrapper for SnappyImage
|
||||
*
|
||||
* @package laravel-snappy
|
||||
* @author Killian Blais
|
||||
*/
|
||||
class ImageWrapper {
|
||||
|
||||
/**
|
||||
* @var \Knp\Snappy\Image
|
||||
*/
|
||||
protected $snappy;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
|
||||
|
||||
/**
|
||||
* @param \Knp\Snappy\Image $snappy
|
||||
*/
|
||||
public function __construct(SnappyImage $snappy)
|
||||
{
|
||||
$this->snappy = $snappy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Snappy instance.
|
||||
*
|
||||
* @return \Knp\Snappy\Image
|
||||
*/
|
||||
public function snappy()
|
||||
{
|
||||
return $this->snappy;
|
||||
}
|
||||
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
$this->snappy->setOption($name, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->snappy->setOptions($options);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a HTML string
|
||||
*
|
||||
* @param string $string
|
||||
* @return static
|
||||
*/
|
||||
public function loadHTML($string)
|
||||
{
|
||||
$this->html = (string) $string;
|
||||
$this->file = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a HTML file
|
||||
*
|
||||
* @param string $file
|
||||
* @return static
|
||||
*/
|
||||
public function loadFile($file)
|
||||
{
|
||||
$this->html = null;
|
||||
$this->file = $file;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function loadView($view, $data = array(), $mergeData = array())
|
||||
{
|
||||
$this->html = View::make($view, $data, $mergeData)->render();
|
||||
$this->file = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the PDF as a string.
|
||||
*
|
||||
* @return string The rendered PDF as string
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function output()
|
||||
{
|
||||
if ($this->html)
|
||||
{
|
||||
return $this->snappy->getOutputFromHtml($this->html, $this->options);
|
||||
}
|
||||
|
||||
if ($this->file)
|
||||
{
|
||||
return $this->snappy->getOutput($this->file, $this->options);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Image Generator requires a html or file in order to produce output.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the image to a file
|
||||
*
|
||||
* @param $filename
|
||||
* @return static
|
||||
*/
|
||||
public function save($filename, $overwrite = false)
|
||||
{
|
||||
|
||||
if ($this->html)
|
||||
{
|
||||
$this->snappy->generateFromHtml($this->html, $filename, $this->options, $overwrite);
|
||||
}
|
||||
elseif ($this->file)
|
||||
{
|
||||
$this->snappy->generate($this->file, $filename, $this->options, $overwrite);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the image downloadable by the user
|
||||
*
|
||||
* @param string $filename
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function download($filename = 'image.jpg')
|
||||
{
|
||||
return new Response($this->output(), 200, array(
|
||||
'Content-Type' => 'image/jpeg',
|
||||
'Content-Disposition' => 'attachment; filename="'.$filename.'"'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a response with the image to show in the browser
|
||||
*
|
||||
* @param string $filename
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inline($filename = 'image.jpg')
|
||||
{
|
||||
return new Response($this->output(), 200, array(
|
||||
'Content-Type' => 'image/jpeg',
|
||||
'Content-Disposition' => 'inline; filename="'.$filename.'"',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a response with the image to show in the browser
|
||||
*
|
||||
* @deprecated Use inline() instead
|
||||
* @param string $filename
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function stream($filename = 'image.jpg')
|
||||
{
|
||||
return new StreamedResponse(function() {
|
||||
echo $this->output();
|
||||
}, 200, array(
|
||||
'Content-Type' => 'image/jpeg',
|
||||
'Content-Disposition' => 'inline; filename="'.$filename.'"',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Call Snappy instance.
|
||||
*
|
||||
* Also shortcut's
|
||||
* ->html => loadHtml
|
||||
* ->view => loadView
|
||||
* ->file => loadFile
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($name, array $arguments)
|
||||
{
|
||||
$method = 'load' . ucfirst($name);
|
||||
if (method_exists($this, $method))
|
||||
{
|
||||
return call_user_func_array(array($this, $method), $arguments);
|
||||
}
|
||||
|
||||
return call_user_func_array (array($this->snappy, $name), $arguments);
|
||||
}
|
||||
}
|
||||
-81
@@ -1,81 +0,0 @@
|
||||
<?php namespace Barryvdh\Snappy;
|
||||
|
||||
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
|
||||
|
||||
class LumenServiceProvider extends BaseServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->configure('snappy');
|
||||
|
||||
$configPath = __DIR__ . '/../config/snappy.php';
|
||||
$this->mergeConfigFrom($configPath, 'snappy');
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
if ($this->app['config']->get('snappy.pdf.enabled')) {
|
||||
$this->app->bind('snappy.pdf',function ($app) {
|
||||
$binary = $app['config']->get('snappy.pdf.binary', '/usr/local/bin/wkhtmltopdf');
|
||||
$options = $app['config']->get('snappy.pdf.options', array());
|
||||
$env = $app['config']->get('snappy.pdf.env', array());
|
||||
$timeout = $app['config']->get('snappy.pdf.timeout', false);
|
||||
|
||||
$snappy = new IlluminateSnappyPdf($app['files'], $binary, $options, $env);
|
||||
if (false !== $timeout) {
|
||||
$snappy->setTimeout($timeout);
|
||||
}
|
||||
|
||||
return $snappy;
|
||||
});
|
||||
|
||||
$this->app->bind('snappy.pdf.wrapper',function ($app) {
|
||||
return new PdfWrapper($app['snappy.pdf']);
|
||||
});
|
||||
$this->app->alias('snappy.pdf.wrapper', 'Barryvdh\Snappy\PdfWrapper');
|
||||
}
|
||||
|
||||
if ($this->app['config']->get('snappy.image.enabled')) {
|
||||
$this->app->bind('snappy.image',function ($app) {
|
||||
$binary = $app['config']->get('snappy.image.binary', '/usr/local/bin/wkhtmltoimage');
|
||||
$options = $app['config']->get('snappy.image.options', array());
|
||||
$env = $app['config']->get('snappy.image.env', array());
|
||||
$timeout = $app['config']->get('snappy.image.timeout', false);
|
||||
|
||||
$image = new IlluminateSnappyImage($app['files'], $binary, $options, $env);
|
||||
if (false !== $timeout) {
|
||||
$image->setTimeout($timeout);
|
||||
}
|
||||
|
||||
return $image;
|
||||
});
|
||||
|
||||
$this->app->bind('snappy.image.wrapper',function ($app) {
|
||||
return new ImageWrapper($app['snappy.image']);
|
||||
});
|
||||
$this->app->alias('snappy.image.wrapper', 'Barryvdh\Snappy\ImageWrapper');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array('snappy.pdf', 'snappy.pdf.wrapper', 'snappy.image', 'snappy.image.wrapper');
|
||||
}
|
||||
}
|
||||
@@ -1,297 +0,0 @@
|
||||
<?php namespace Barryvdh\Snappy;
|
||||
|
||||
use Illuminate\View\View;
|
||||
use PHPUnit\Framework\Assert as PHPUnit;
|
||||
use Illuminate\Support\Facades\View as ViewFacade;
|
||||
|
||||
|
||||
class PdfFaker extends PdfWrapper
|
||||
{
|
||||
protected $view;
|
||||
protected $filename;
|
||||
|
||||
/**
|
||||
* Load a View and convert to HTML
|
||||
*
|
||||
* @param string $view
|
||||
* @param array $data
|
||||
* @param array $mergeData
|
||||
* @return $this
|
||||
*/
|
||||
public function loadView($view, $data = array(), $mergeData = array())
|
||||
{
|
||||
$this->view = ViewFacade::make($view, $data, $mergeData);
|
||||
return parent::loadView($view, $data, $mergeData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ensure that the response has a view as its original content.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function ensureResponseHasView()
|
||||
{
|
||||
if (! isset($this->view) || ! $this->view instanceof View) {
|
||||
return PHPUnit::fail('The response is not a view.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function assertViewIs($value)
|
||||
{
|
||||
PHPUnit::assertEquals($value, $this->view->getName());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the response view has a given piece of bound data.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @param mixed $value
|
||||
* @return $this
|
||||
*/
|
||||
public function assertViewHas($key, $value = null)
|
||||
{
|
||||
if (is_array($key)) {
|
||||
return $this->assertViewHasAll($key);
|
||||
}
|
||||
|
||||
$this->ensureResponseHasView();
|
||||
|
||||
if (is_null($value)) {
|
||||
PHPUnit::assertArrayHasKey($key, $this->view->getData());
|
||||
} elseif ($value instanceof \Closure) {
|
||||
PHPUnit::assertTrue($value($this->view->$key));
|
||||
} else {
|
||||
PHPUnit::assertEquals($value, $this->view->$key);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the response view has a given list of bound data.
|
||||
*
|
||||
* @param array $bindings
|
||||
* @return $this
|
||||
*/
|
||||
public function assertViewHasAll(array $bindings)
|
||||
{
|
||||
foreach ($bindings as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
$this->assertViewHas($value);
|
||||
} else {
|
||||
$this->assertViewHas($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the response view is missing a piece of bound data.
|
||||
*
|
||||
* @param string $key
|
||||
* @return $this
|
||||
*/
|
||||
public function assertViewMissing($key)
|
||||
{
|
||||
$this->ensureResponseHasView();
|
||||
|
||||
PHPUnit::assertArrayNotHasKey($key, $this->view->getData());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given string is contained within the response.
|
||||
*
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function assertSee($value)
|
||||
{
|
||||
PHPUnit::assertStringContainsString($value, $this->html);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given string is contained within the response text.
|
||||
*
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function assertSeeText($value)
|
||||
{
|
||||
PHPUnit::assertStringContainsString($value, strip_tags($this->html));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given string is not contained within the response.
|
||||
*
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function assertDontSee($value)
|
||||
{
|
||||
PHPUnit::assertStringNotContainsString($value, $this->html);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given string is not contained within the response text.
|
||||
*
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function assertDontSeeText($value)
|
||||
{
|
||||
PHPUnit::assertStringNotContainsString($value, strip_tags($this->html));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given string is equal to the saved filename.
|
||||
*
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function assertFileNameIs($value)
|
||||
{
|
||||
PHPUnit::assertEquals($value, $this->filename);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function output()
|
||||
{
|
||||
return '%PDF-1.3
|
||||
%?????????
|
||||
4 0 obj
|
||||
<< /Length 5 0 R /Filter /FlateDecode >>
|
||||
stream
|
||||
x+T(T0BSKS=#
|
||||
|
||||
C=
|
||||
K??T?p?<}?bC??bC0,N??5?34???05j1?7)N?
|
||||
z/?
|
||||
endstream
|
||||
endobj
|
||||
5 0 obj
|
||||
73
|
||||
endobj
|
||||
2 0 obj
|
||||
<< /Type /Page /Parent 3 0 R /Resources 6 0 R /Contents 4 0 R /MediaBox [0 0 595.28 841.89]
|
||||
>>
|
||||
endobj
|
||||
6 0 obj
|
||||
<< /ProcSet [ /PDF ] /ColorSpace << /Cs1 7 0 R >> >>
|
||||
endobj
|
||||
8 0 obj
|
||||
<< /Length 9 0 R /N 3 /Alternate /DeviceRGB /Filter /FlateDecode >>
|
||||
stream
|
||||
x??wTS??Ͻ7??" %?z ?;HQ?I?P??&vDF)VdT?G?"cE
|
||||
??b? ?P??QDE?k ?5?ޚ??Y?????g?}P???tX?4?X???\???X??ffG?D???=???HƳ??.?d??,?P&s???"7C$
|
||||
E?6<~&??S??2????)2?12? ??"?įl???+?ɘ?&?Y??4???Pޚ%ᣌ?\?%?g?|e?TI???(????L0?_??&?l?2E???9?r??9h?x?g??Ib?טi???f??S?b1+??M?xL???
|
||||
?0??o?E%Ym?h?????Y??h????~S?=?z?U?&?ϞA??Y?l?/??$Z????U?m@??O? ??ޜ??l^???
|
||||
\'
|
||||
???ls?k.+?7???oʿ?9?????V;???#I3eE妧?KD??
|
||||
??d?????9i???,?????UQ? ??h??<?X?.d
|
||||
???6\'~?khu_}?9P?I?o=C#$n?z}?[1
|
||||
Ⱦ?h???s?2z???
|
||||
\?n?LA"S??
|
||||
?dr%?,?߄l??t?
|
||||
?3p? ??H?.Hi@?A>?
|
||||
p1?v?jpԁz?N?6p\W?
|
||||
|
||||
?G@
|
||||
???ٰG???Dx????J?>???,?_@?FDB?X$!k?"??E????H?q???a???Y??bVa?bJ0c?VL?6f3????bձ?X\'??&?x?*???s?b|!??`[????a?;???p~?\2n5??????
|
||||
ߏƿ\'? Zk?!? $l$???4Q??Ot"?y?\b)???A?I&N?I?$R$)???TIj"]&=&?!??:dGrY@^O?$? _%??P?n?X????ZO?D}J}/G?3???ɭ???k??{%O?חw?_.?\'_!J????Q?@?S???V?F??=?IE???b?b?b?b??5?Q%?????O?@??%?!BӥyҸ?M?:?e?0G7??ӓ????? e%e[?(????R?0`?3R????????4?????6?i^??)??*n*|?"?f????LUo?՝?m?O?0j&jaj?j??.??ϧ?w?ϝ_4????갺?z??j???=???U?4?5?n?ɚ??4ǴhZ
|
||||
?Z?Z?^0????Tf%??9?????-?>?ݫ=?c??Xg?N??]?.[7A?\?SwBOK/X/_?Q?>Q?????G?[??? ?`?A???????a?a??c#????*?Z?;?8c?q??>?[&???I?I??MS???T`?ϴ?
|
||||
k?h&4?5?Ǣ??YY?F֠9?<?|?y??+
|
||||
=?X???_,?,S-?,Y)YXm?????Ěk]c}džj?c?Φ?浭?-?v??};?]???N????"?&?1=?x????tv(??}???????\'{\'??I?ߝY?Σ?
|
||||
|
||||
??-r?q?r?.d.?_xp??Uە?Z???M?v?m???=????+K?G?ǔ????
|
||||
^???W?W????b?j?>:>?>?>?v??}/?a??v?????????O8? ?
|
||||
?FV>
|
||||
2 u?????/?_$\?B?Cv?< 5
|
||||
]?s.,4?&?y?Ux~xw-bEDCĻH????G??KwF?G?E?GME{E?EK?X,Y??F?Z? ?=$vr????K????
|
||||
??.3\????r???Ϯ?_?Yq*??©?L??_?w?ד??????+??]?e???????D??]?cI?II?OA??u?_?䩔???)3?ѩ?i?????B%a??+]3=\'?/?4?0C??i??U?@ёL(sYf????L?H?$?%?Y
|
||||
?j??gGe??Q?????n?????~5f5wug?v????5?k??֮\۹Nw]??????m mH???Fˍen???Q?Q??`h????B?BQ?-?[l?ll??f??jۗ"^??b???O%ܒ??Y}W???????????w?w????X?bY^?Ю?]?????W?Va[q`i?d??2???J?jGէ??????{??????m???>???Pk?Am?a?????꺿g_D?H??G?G??u?;??7?7?6?Ʊ?q?o???C{??P3???8!9?????
|
||||
<?y?}??\'?????Z?Z???։??6i{L{??ӝ?-???|??????gKϑ???9?w~?Bƅ??:Wt>???ҝ????ˁ??^?r?۽??U??g?9];}?}????????_?~i??m??p???㭎?}??]?/???}?????.?{?^?=?}????^??z8?h?c??\'
|
||||
O*????????f?????`ϳ?g???C/????O?ϩ?+F?F?G?Gό???z????ˌ??ㅿ)????ѫ?~w??gb???k???Jި?9???m?d???wi獵?ޫ???????c?Ǒ??O?O????w| ??x&mf??????
|
||||
endstream
|
||||
endobj
|
||||
9 0 obj
|
||||
2612
|
||||
endobj
|
||||
7 0 obj
|
||||
[ /ICCBased 8 0 R ]
|
||||
endobj
|
||||
3 0 obj
|
||||
<< /Type /Pages /MediaBox [0 0 595.28 841.89] /Count 1 /Kids [ 2 0 R ] >>
|
||||
endobj
|
||||
10 0 obj
|
||||
<< /Type /Catalog /Pages 3 0 R >>
|
||||
endobj
|
||||
11 0 obj
|
||||
(Leeg)
|
||||
endobj
|
||||
12 0 obj
|
||||
(Mac OS X 10.13.3 Quartz PDFContext)
|
||||
endobj
|
||||
13 0 obj
|
||||
(Pages)
|
||||
endobj
|
||||
14 0 obj
|
||||
(D:20180330091154Z00\'00\')
|
||||
endobj
|
||||
1 0 obj
|
||||
<< /Title 11 0 R /Producer 12 0 R /Creator 13 0 R /CreationDate 14 0 R /ModDate
|
||||
14 0 R >>
|
||||
endobj
|
||||
xref
|
||||
0 15
|
||||
0000000000 65535 f
|
||||
0000003414 00000 n
|
||||
0000000187 00000 n
|
||||
0000003133 00000 n
|
||||
0000000022 00000 n
|
||||
0000000169 00000 n
|
||||
0000000297 00000 n
|
||||
0000003098 00000 n
|
||||
0000000365 00000 n
|
||||
0000003078 00000 n
|
||||
0000003222 00000 n
|
||||
0000003272 00000 n
|
||||
0000003295 00000 n
|
||||
0000003348 00000 n
|
||||
0000003372 00000 n
|
||||
trailer
|
||||
<< /Size 15 /Root 10 0 R /Info 1 0 R /ID [ <ea5d2c625a19688ce1ff05174d8a0261>
|
||||
<ea5d2c625a19688ce1ff05174d8a0261> ] >>
|
||||
startxref
|
||||
3519
|
||||
%%EOF';
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the PDF to a file
|
||||
*
|
||||
* @param $filename
|
||||
* @return $this
|
||||
*/
|
||||
public function save($filename, $overwrite = false)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -1,285 +0,0 @@
|
||||
<?php namespace Barryvdh\Snappy;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Knp\Snappy\Pdf as SnappyPDF;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
/**
|
||||
* A Laravel wrapper for SnappyPDF
|
||||
*
|
||||
* @package laravel-snappy
|
||||
* @author Barry vd. Heuvel
|
||||
*/
|
||||
class PdfWrapper{
|
||||
|
||||
/**
|
||||
* @var \Knp\Snappy\Pdf
|
||||
*/
|
||||
protected $snappy;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $html;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $file;
|
||||
|
||||
/**
|
||||
* @param \Knp\Snappy\Pdf $snappy
|
||||
*/
|
||||
public function __construct(SnappyPDF $snappy)
|
||||
{
|
||||
$this->snappy = $snappy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Snappy instance.
|
||||
*
|
||||
* @return \Knp\Snappy\Pdf
|
||||
*/
|
||||
public function snappy()
|
||||
{
|
||||
return $this->snappy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set temporary folder
|
||||
*
|
||||
* @param string $path
|
||||
*/
|
||||
public function setTemporaryFolder($path)
|
||||
{
|
||||
$this->snappy->setTemporaryFolder($path);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the paper size (default A4)
|
||||
*
|
||||
* @param string $paper
|
||||
* @param string $orientation
|
||||
* @return $this
|
||||
*/
|
||||
public function setPaper($paper, $orientation=null)
|
||||
{
|
||||
$this->snappy->setOption('page-size', $paper);
|
||||
if($orientation){
|
||||
$this->snappy->setOption('orientation', $orientation);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the orientation (default portrait)
|
||||
*
|
||||
* @param string $orientation
|
||||
* @return $this
|
||||
*/
|
||||
public function setOrientation($orientation)
|
||||
{
|
||||
$this->snappy->setOption('orientation', $orientation);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show or hide warnings
|
||||
*
|
||||
* @param bool $warnings
|
||||
* @return $this
|
||||
* @deprecated
|
||||
*/
|
||||
public function setWarnings($warnings)
|
||||
{
|
||||
//Doesn't do anything
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if ($value instanceof Renderable) {
|
||||
$value = $value->render();
|
||||
}
|
||||
$this->snappy->setOption($name, $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
* @return $this
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->snappy->setOptions($options);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a HTML string
|
||||
*
|
||||
* @param Array|string|Renderable $html
|
||||
* @return $this
|
||||
*/
|
||||
public function loadHTML($html)
|
||||
{
|
||||
if ($html instanceof Renderable) {
|
||||
$html = $html->render();
|
||||
}
|
||||
$this->html = $html;
|
||||
$this->file = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a HTML file
|
||||
*
|
||||
* @param string $file
|
||||
* @return $this
|
||||
*/
|
||||
public function loadFile($file)
|
||||
{
|
||||
$this->html = null;
|
||||
$this->file = $file;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a View and convert to HTML
|
||||
*
|
||||
* @param string $view
|
||||
* @param array $data
|
||||
* @param array $mergeData
|
||||
* @return $this
|
||||
*/
|
||||
public function loadView($view, $data = array(), $mergeData = array())
|
||||
{
|
||||
$view = View::make($view, $data, $mergeData);
|
||||
|
||||
return $this->loadHTML($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the PDF as a string.
|
||||
*
|
||||
* @return string The rendered PDF as string
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function output()
|
||||
{
|
||||
if ($this->html)
|
||||
{
|
||||
return $this->snappy->getOutputFromHtml($this->html, $this->options);
|
||||
}
|
||||
|
||||
if ($this->file)
|
||||
{
|
||||
return $this->snappy->getOutput($this->file, $this->options);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('PDF Generator requires a html or file in order to produce output.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the PDF to a file
|
||||
*
|
||||
* @param $filename
|
||||
* @return $this
|
||||
*/
|
||||
public function save($filename, $overwrite = false)
|
||||
{
|
||||
|
||||
if ($this->html)
|
||||
{
|
||||
$this->snappy->generateFromHtml($this->html, $filename, $this->options, $overwrite);
|
||||
}
|
||||
elseif ($this->file)
|
||||
{
|
||||
$this->snappy->generate($this->file, $filename, $this->options, $overwrite);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the PDF downloadable by the user
|
||||
*
|
||||
* @param string $filename
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function download($filename = 'document.pdf')
|
||||
{
|
||||
return new Response($this->output(), 200, array(
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'attachment; filename="'.$filename.'"'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a response with the PDF to show in the browser
|
||||
*
|
||||
* @param string $filename
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function inline($filename = 'document.pdf')
|
||||
{
|
||||
return new Response($this->output(), 200, array(
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="'.$filename.'"',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a response with the PDF to show in the browser
|
||||
*
|
||||
* @param string $filename
|
||||
* @return \Symfony\Component\HttpFoundation\StreamedResponse
|
||||
* @deprecated use inline() instead
|
||||
*/
|
||||
public function stream($filename = 'document.pdf')
|
||||
{
|
||||
return new StreamedResponse(function() {
|
||||
echo $this->output();
|
||||
}, 200, array(
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="'.$filename.'"',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Call Snappy instance.
|
||||
*
|
||||
* Also shortcut's
|
||||
* ->html => loadHtml
|
||||
* ->view => loadView
|
||||
* ->file => loadFile
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($name, array $arguments)
|
||||
{
|
||||
$method = 'load' . ucfirst($name);
|
||||
if (method_exists($this, $method))
|
||||
{
|
||||
return call_user_func_array(array($this, $method), $arguments);
|
||||
}
|
||||
|
||||
return call_user_func_array (array($this->snappy, $name), $arguments);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php namespace Barryvdh\Snappy;
|
||||
|
||||
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
|
||||
|
||||
class ServiceProvider extends BaseServiceProvider {
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$configPath = __DIR__ . '/../config/snappy.php';
|
||||
$this->mergeConfigFrom($configPath, 'snappy');
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
$configPath = __DIR__ . '/../config/snappy.php';
|
||||
$this->publishes([$configPath => config_path('snappy.php')], 'config');
|
||||
|
||||
if($this->app['config']->get('snappy.pdf.enabled')){
|
||||
$this->app->bind('snappy.pdf', function($app)
|
||||
{
|
||||
$binary = $app['config']->get('snappy.pdf.binary', '/usr/local/bin/wkhtmltopdf');
|
||||
$options = $app['config']->get('snappy.pdf.options', array());
|
||||
$env = $app['config']->get('snappy.pdf.env', array());
|
||||
$timeout = $app['config']->get('snappy.pdf.timeout', false);
|
||||
|
||||
$snappy = new IlluminateSnappyPdf($app['files'], $binary, $options, $env);
|
||||
if (false !== $timeout) {
|
||||
$snappy->setTimeout($timeout);
|
||||
}
|
||||
|
||||
return $snappy;
|
||||
});
|
||||
|
||||
$this->app->bind('snappy.pdf.wrapper', function($app)
|
||||
{
|
||||
return new PdfWrapper($app['snappy.pdf']);
|
||||
});
|
||||
$this->app->alias('snappy.pdf.wrapper', 'Barryvdh\Snappy\PdfWrapper');
|
||||
}
|
||||
|
||||
|
||||
if($this->app['config']->get('snappy.image.enabled')){
|
||||
$this->app->bind('snappy.image', function($app)
|
||||
{
|
||||
$binary = $app['config']->get('snappy.image.binary', '/usr/local/bin/wkhtmltoimage');
|
||||
$options = $app['config']->get('snappy.image.options', array());
|
||||
$env = $app['config']->get('snappy.image.env', array());
|
||||
$timeout = $app['config']->get('snappy.image.timeout', false);
|
||||
|
||||
$image = new IlluminateSnappyImage($app['files'], $binary, $options, $env);
|
||||
if (false !== $timeout) {
|
||||
$image->setTimeout($timeout);
|
||||
}
|
||||
|
||||
return $image;
|
||||
});
|
||||
|
||||
$this->app->bind('snappy.image.wrapper', function($app)
|
||||
{
|
||||
return new ImageWrapper($app['snappy.image']);
|
||||
});
|
||||
$this->app->alias('snappy.image.wrapper', 'Barryvdh\Snappy\ImageWrapper');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array('snappy.pdf', 'snappy.pdf.wrapper', 'snappy.image', 'snappy.image.wrapper');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user