Subiendo proyecto completo sin restricciones de git ignore
This commit is contained in:
25
vendor/niklasravnsborg/laravel-pdf/.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
25
vendor/niklasravnsborg/laravel-pdf/.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
We are only able to handle bug reports at this point in time. If you have an idea on how to improve the library, please submit a pull request.
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Use this method '...'
|
||||
2. Download PDF '....'
|
||||
3. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
2
vendor/niklasravnsborg/laravel-pdf/.gitignore
vendored
Normal file
2
vendor/niklasravnsborg/laravel-pdf/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
vendor/
|
||||
composer.lock
|
||||
192
vendor/niklasravnsborg/laravel-pdf/README.md
vendored
Normal file
192
vendor/niklasravnsborg/laravel-pdf/README.md
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
# Laravel PDF: mPDF wrapper for Laravel 5
|
||||
|
||||
> Easily generate PDF documents from HTML right inside of Laravel using this mPDF wrapper.
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Require this package in your `composer.json` or install it by running:
|
||||
|
||||
```
|
||||
composer require niklasravnsborg/laravel-pdf
|
||||
```
|
||||
|
||||
> Note: This package supports auto-discovery features of Laravel 5.5+, You only need to manually add the service provider and alias if working on Laravel version lower then 5.5
|
||||
|
||||
To start using Laravel, add the Service Provider and the Facade to your `config/app.php`:
|
||||
|
||||
```php
|
||||
'providers' => [
|
||||
// ...
|
||||
niklasravnsborg\LaravelPdf\PdfServiceProvider::class
|
||||
]
|
||||
```
|
||||
|
||||
```php
|
||||
'aliases' => [
|
||||
// ...
|
||||
'PDF' => niklasravnsborg\LaravelPdf\Facades\Pdf::class
|
||||
]
|
||||
```
|
||||
|
||||
Now, you should publish package's config file to your config directory by using following command:
|
||||
|
||||
```
|
||||
php artisan vendor:publish
|
||||
```
|
||||
|
||||
## Basic Usage
|
||||
|
||||
To use Laravel PDF add something like this to one of your controllers. You can pass data to a view in `/resources/views`.
|
||||
|
||||
```php
|
||||
use PDF;
|
||||
|
||||
function generate_pdf() {
|
||||
$data = [
|
||||
'foo' => 'bar'
|
||||
];
|
||||
$pdf = PDF::loadView('pdf.document', $data);
|
||||
return $pdf->stream('document.pdf');
|
||||
}
|
||||
```
|
||||
|
||||
## Other methods
|
||||
|
||||
It is also possible to use the following methods on the `pdf` object:
|
||||
|
||||
`output()`: Outputs the PDF as a string.
|
||||
`save($filename)`: Save the PDF to a file
|
||||
`download($filename)`: Make the PDF downloadable by the user.
|
||||
`stream($filename)`: Return a response with the PDF to show in the browser.
|
||||
|
||||
## Config
|
||||
|
||||
If you have published config file, you can change the default settings in `config/pdf.php` file:
|
||||
|
||||
```php
|
||||
return [
|
||||
'format' => 'A4', // See https://mpdf.github.io/paging/page-size-orientation.html
|
||||
'author' => 'John Doe',
|
||||
'subject' => 'This Document will explain the whole universe.',
|
||||
'keywords' => 'PDF, Laravel, Package, Peace', // Separate values with comma
|
||||
'creator' => 'Laravel Pdf',
|
||||
'display_mode' => 'fullpage'
|
||||
];
|
||||
```
|
||||
|
||||
To override this configuration on a per-file basis use the fourth parameter of the initializing call like this:
|
||||
|
||||
```php
|
||||
PDF::loadView('pdf', $data, [], [
|
||||
'format' => 'A5-L'
|
||||
])->save($pdfFilePath);
|
||||
```
|
||||
|
||||
You can use a callback with the key 'instanceConfigurator' to access mpdf functions:
|
||||
```php
|
||||
$config = ['instanceConfigurator' => function($mpdf) {
|
||||
$mpdf->SetImportUse();
|
||||
$mpdf->SetDocTemplate(/path/example.pdf, true);
|
||||
}]
|
||||
|
||||
PDF::loadView('pdf', $data, [], $config)->save($pdfFilePath);
|
||||
```
|
||||
|
||||
## Headers and Footers
|
||||
|
||||
If you want to have headers and footers that appear on every page, add them to your `<body>` tag like this:
|
||||
|
||||
```html
|
||||
<htmlpageheader name="page-header">
|
||||
Your Header Content
|
||||
</htmlpageheader>
|
||||
|
||||
<htmlpagefooter name="page-footer">
|
||||
Your Footer Content
|
||||
</htmlpagefooter>
|
||||
```
|
||||
|
||||
Now you just need to define them with the name attribute in your CSS:
|
||||
|
||||
```css
|
||||
@page {
|
||||
header: page-header;
|
||||
footer: page-footer;
|
||||
}
|
||||
```
|
||||
|
||||
Inside of headers and footers `{PAGENO}` can be used to display the page number.
|
||||
|
||||
## Included Fonts
|
||||
|
||||
By default you can use all the fonts [shipped with mPDF](https://mpdf.github.io/fonts-languages/available-fonts-v6.html).
|
||||
|
||||
## Custom Fonts
|
||||
|
||||
You can use your own fonts in the generated PDFs. The TTF files have to be located in one folder, e.g. `/resources/fonts/`. Add this to your configuration file (`/config/pdf.php`):
|
||||
|
||||
```php
|
||||
return [
|
||||
// ...
|
||||
'font_path' => base_path('resources/fonts/'),
|
||||
'font_data' => [
|
||||
'examplefont' => [
|
||||
'R' => 'ExampleFont-Regular.ttf', // regular font
|
||||
'B' => 'ExampleFont-Bold.ttf', // optional: bold font
|
||||
'I' => 'ExampleFont-Italic.ttf', // optional: italic font
|
||||
'BI' => 'ExampleFont-Bold-Italic.ttf' // optional: bold-italic font
|
||||
//'useOTL' => 0xFF, // required for complicated langs like Persian, Arabic and Chinese
|
||||
//'useKashida' => 75, // required for complicated langs like Persian, Arabic and Chinese
|
||||
]
|
||||
// ...add as many as you want.
|
||||
]
|
||||
// ...
|
||||
];
|
||||
```
|
||||
|
||||
*Note*: If you are using `laravel-pdf` for producing PDF documents in a complicated language (like Persian, Arabic or Chinese) you should have `useOTL` and `useKashida` indexes in your custom font definition array. If you do not use these indexes, your characters will be shown dispatched and incorrectly in the produced PDF.
|
||||
|
||||
Now you can use the font in CSS:
|
||||
|
||||
```css
|
||||
body {
|
||||
font-family: 'examplefont', sans-serif;
|
||||
}
|
||||
```
|
||||
|
||||
## Set Protection
|
||||
|
||||
To set protection, you just call the `SetProtection()` method and pass an array with permissions, an user password and an owner password.
|
||||
|
||||
The passwords are optional.
|
||||
|
||||
There are a fews permissions: `'copy'`, `'print'`, `'modify'`, `'annot-forms'`, `'fill-forms'`, `'extract'`, `'assemble'`, `'print-highres'`.
|
||||
|
||||
```php
|
||||
use PDF;
|
||||
|
||||
function generate_pdf() {
|
||||
$data = [
|
||||
'foo' => 'bar'
|
||||
];
|
||||
$pdf = PDF::loadView('pdf.document', $data);
|
||||
$pdf->SetProtection(['copy', 'print'], '', 'pass');
|
||||
return $pdf->stream('document.pdf');
|
||||
}
|
||||
```
|
||||
|
||||
Find more information to `SetProtection()` here: https://mpdf.github.io/reference/mpdf-functions/setprotection.html
|
||||
|
||||
## Testing
|
||||
|
||||
To use the testing suite, you need some extensions and binaries for your local PHP. On macOS, you can install them like this:
|
||||
|
||||
```
|
||||
brew install imagemagick ghostscript
|
||||
pecl install imagick
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Laravel PDF is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
|
||||
37
vendor/niklasravnsborg/laravel-pdf/composer.json
vendored
Normal file
37
vendor/niklasravnsborg/laravel-pdf/composer.json
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "niklasravnsborg/laravel-pdf",
|
||||
"description": "Generate PDFs in Laravel with this mPDF wrapper.",
|
||||
"keywords": ["mpdf", "pdf", "laravel"],
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "phpunit --colors=always"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.0",
|
||||
"mpdf/mpdf": "^8.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"niklasravnsborg\\LaravelPdf\\": "src/LaravelPdf"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"niklasravnsborg\\LaravelPdf\\Test\\": "tests/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"niklasravnsborg\\LaravelPdf\\PdfServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"PDF": "niklasravnsborg\\LaravelPdf\\Facades\\Pdf"
|
||||
}
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.4",
|
||||
"orchestra/testbench": "^3.7"
|
||||
}
|
||||
}
|
||||
22
vendor/niklasravnsborg/laravel-pdf/phpunit.xml
vendored
Normal file
22
vendor/niklasravnsborg/laravel-pdf/phpunit.xml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="vendor/autoload.php"
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
verbose="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false">
|
||||
<testsuites>
|
||||
<testsuite name="default">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">src/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
15
vendor/niklasravnsborg/laravel-pdf/src/LaravelPdf/Facades/Pdf.php
vendored
Normal file
15
vendor/niklasravnsborg/laravel-pdf/src/LaravelPdf/Facades/Pdf.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace niklasravnsborg\LaravelPdf\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade as BaseFacade;
|
||||
|
||||
class Pdf extends BaseFacade {
|
||||
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor() { return 'mpdf.wrapper'; }
|
||||
}
|
||||
154
vendor/niklasravnsborg/laravel-pdf/src/LaravelPdf/Pdf.php
vendored
Normal file
154
vendor/niklasravnsborg/laravel-pdf/src/LaravelPdf/Pdf.php
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace niklasravnsborg\LaravelPdf;
|
||||
|
||||
use Config;
|
||||
use Mpdf;
|
||||
|
||||
/**
|
||||
* Laravel PDF: mPDF wrapper for Laravel 5
|
||||
*
|
||||
* @package laravel-pdf
|
||||
* @author Niklas Ravnsborg-Gjertsen
|
||||
*/
|
||||
class Pdf {
|
||||
|
||||
protected $config = [];
|
||||
|
||||
public function __construct($html = '', $config = [])
|
||||
{
|
||||
$this->config = $config;
|
||||
|
||||
// @see https://mpdf.github.io/reference/mpdf-functions/construct.html
|
||||
$mpdf_config = [
|
||||
'mode' => $this->getConfig('mode'), // Mode of the document.
|
||||
'format' => $this->getConfig('format'), // Can be specified either as a pre-defined page size, or as an array of width and height in millimetres
|
||||
'default_font_size' => $this->getConfig('default_font_size'), // Sets the default document font size in points (pt).
|
||||
'default_font' => $this->getConfig('default_font'), // Sets the default font-family for the new document.
|
||||
'margin_left' => $this->getConfig('margin_left'), // Set the page margins for the new document.
|
||||
'margin_right' => $this->getConfig('margin_right'), // Set the page margins for the new document.
|
||||
'margin_top' => $this->getConfig('margin_top'), // Set the page margins for the new document.
|
||||
'margin_bottom' => $this->getConfig('margin_bottom'), // Set the page margins for the new document.
|
||||
'margin_header' => $this->getConfig('margin_header'), // Set the page margins for the new document.
|
||||
'margin_footer' => $this->getConfig('margin_footer'), // Set the page margins for the new document.
|
||||
'orientation' => $this->getConfig('orientation'), // This attribute specifies the default page orientation of the new document if format is defined as an array. This value will be ignored if format is a string value.
|
||||
'tempDir' => $this->getConfig('tempDir') // temporary directory
|
||||
];
|
||||
|
||||
// Handle custom fonts
|
||||
$mpdf_config = $this->addCustomFontsConfig($mpdf_config);
|
||||
|
||||
$this->mpdf = new Mpdf\Mpdf($mpdf_config);
|
||||
|
||||
// If you want to change your document title,
|
||||
// please use the <title> tag.
|
||||
$this->mpdf->SetTitle('Document');
|
||||
|
||||
$this->mpdf->SetAuthor ( $this->getConfig('author') );
|
||||
$this->mpdf->SetCreator ( $this->getConfig('creator') );
|
||||
$this->mpdf->SetSubject ( $this->getConfig('subject') );
|
||||
$this->mpdf->SetKeywords ( $this->getConfig('keywords') );
|
||||
$this->mpdf->SetDisplayMode ( $this->getConfig('display_mode') );
|
||||
|
||||
if (!empty($this->getConfig('pdf_a'))) {
|
||||
$this->mpdf->PDFA = $this->getConfig('pdf_a'); // Set the flag whether you want to use the pdfA-1b format
|
||||
$this->mpdf->PDFAauto = $this->getConfig('pdf_a_auto'); // Overrides warnings making changes when possible to force PDFA1-b compliance;
|
||||
}
|
||||
|
||||
if (!empty($this->getConfig('icc_profile_path'))) {
|
||||
$this->mpdf->ICCProfile = $this->getConfig('icc_profile_path'); // Specify ICC colour profile
|
||||
}
|
||||
|
||||
if (isset($this->config['instanceConfigurator']) && is_callable(($this->config['instanceConfigurator']))) {
|
||||
$this->config['instanceConfigurator']($this->mpdf);
|
||||
}
|
||||
|
||||
$this->mpdf->WriteHTML($html);
|
||||
}
|
||||
|
||||
protected function getConfig($key)
|
||||
{
|
||||
if (isset($this->config[$key])) {
|
||||
return $this->config[$key];
|
||||
} else {
|
||||
return Config::get('pdf.' . $key);
|
||||
}
|
||||
}
|
||||
|
||||
protected function addCustomFontsConfig($mpdf_config)
|
||||
{
|
||||
if (!Config::has('pdf.font_path') || !Config::has('pdf.font_data')) {
|
||||
return $mpdf_config;
|
||||
}
|
||||
|
||||
// Get default font configuration
|
||||
$fontDirs = (new Mpdf\Config\ConfigVariables())->getDefaults()['fontDir'];
|
||||
$fontData = (new Mpdf\Config\FontVariables())->getDefaults()['fontdata'];
|
||||
|
||||
// Merge default with custom configuration
|
||||
$mpdf_config['fontDir'] = array_merge($fontDirs, [Config::get('pdf.font_path')]);
|
||||
$mpdf_config['fontdata'] = array_merge($fontData, Config::get('pdf.font_data'));
|
||||
|
||||
return $mpdf_config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypts and sets the PDF document permissions
|
||||
*
|
||||
* @param array $permisson Permissons e.g.: ['copy', 'print']
|
||||
* @param string $userPassword User password
|
||||
* @param string $ownerPassword Owner password
|
||||
* @return static
|
||||
*
|
||||
*/
|
||||
public function setProtection($permisson, $userPassword = '', $ownerPassword = '')
|
||||
{
|
||||
if (func_get_args()[2] === NULL) {
|
||||
$ownerPassword = bin2hex(openssl_random_pseudo_bytes(8));
|
||||
};
|
||||
return $this->mpdf->SetProtection($permisson, $userPassword, $ownerPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the PDF as a string.
|
||||
*
|
||||
* @return string The rendered PDF as string
|
||||
*/
|
||||
public function output()
|
||||
{
|
||||
return $this->mpdf->Output('', 'S');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the PDF to a file
|
||||
*
|
||||
* @param $filename
|
||||
* @return static
|
||||
*/
|
||||
public function save($filename)
|
||||
{
|
||||
return $this->mpdf->Output($filename, 'F');
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the PDF downloadable by the user
|
||||
*
|
||||
* @param string $filename
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function download($filename = 'document.pdf')
|
||||
{
|
||||
return $this->mpdf->Output($filename, 'D');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a response with the PDF to show in the browser
|
||||
*
|
||||
* @param string $filename
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function stream($filename = 'document.pdf')
|
||||
{
|
||||
return $this->mpdf->Output($filename, 'I');
|
||||
}
|
||||
}
|
||||
56
vendor/niklasravnsborg/laravel-pdf/src/LaravelPdf/PdfServiceProvider.php
vendored
Normal file
56
vendor/niklasravnsborg/laravel-pdf/src/LaravelPdf/PdfServiceProvider.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace niklasravnsborg\LaravelPdf;
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
|
||||
|
||||
class PdfServiceProvider extends BaseServiceProvider {
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
|
||||
/*
|
||||
* Bootstrap the application service
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->publishes([
|
||||
__DIR__ . '/../config/pdf.php' => config_path('pdf.php'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->mergeConfigFrom(
|
||||
__DIR__ . '/../config/pdf.php', 'pdf'
|
||||
);
|
||||
|
||||
$this->app->bind('mpdf.wrapper', function($app) {
|
||||
return new PdfWrapper();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array('mpdf.pdf');
|
||||
}
|
||||
|
||||
}
|
||||
45
vendor/niklasravnsborg/laravel-pdf/src/LaravelPdf/PdfWrapper.php
vendored
Normal file
45
vendor/niklasravnsborg/laravel-pdf/src/LaravelPdf/PdfWrapper.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace niklasravnsborg\LaravelPdf;
|
||||
|
||||
use File;
|
||||
use View;
|
||||
|
||||
class PdfWrapper {
|
||||
|
||||
/**
|
||||
* Load a HTML string
|
||||
*
|
||||
* @param string $html
|
||||
* @return Pdf
|
||||
*/
|
||||
public function loadHTML($html, $config = [])
|
||||
{
|
||||
return new Pdf($html, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a HTML file
|
||||
*
|
||||
* @param string $file
|
||||
* @return Pdf
|
||||
*/
|
||||
public function loadFile($file, $config = [])
|
||||
{
|
||||
return new Pdf(File::get($file), $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a View and convert to HTML
|
||||
*
|
||||
* @param string $view
|
||||
* @param array $data
|
||||
* @param array $mergeData
|
||||
* @return Pdf
|
||||
*/
|
||||
public function loadView($view, $data = [], $mergeData = [], $config = [])
|
||||
{
|
||||
return new Pdf(View::make($view, $data, $mergeData)->render(), $config);
|
||||
}
|
||||
|
||||
}
|
||||
15
vendor/niklasravnsborg/laravel-pdf/src/config/pdf.php
vendored
Normal file
15
vendor/niklasravnsborg/laravel-pdf/src/config/pdf.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'mode' => 'utf-8',
|
||||
'format' => 'A4',
|
||||
'author' => '',
|
||||
'subject' => '',
|
||||
'keywords' => '',
|
||||
'creator' => 'Laravel Pdf',
|
||||
'display_mode' => 'fullpage',
|
||||
'tempDir' => base_path('../temp/'),
|
||||
'pdf_a' => false,
|
||||
'pdf_a_auto' => false,
|
||||
'icc_profile_path' => ''
|
||||
];
|
||||
5
vendor/niklasravnsborg/laravel-pdf/src/mpdf_ttfonts_config.php
vendored
Normal file
5
vendor/niklasravnsborg/laravel-pdf/src/mpdf_ttfonts_config.php
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
define('_MPDF_SYSTEM_TTFONTS', Config::get('pdf.custom_font_path'));
|
||||
$this->fontdata = array_merge($this->fontdata, Config::get('pdf.custom_font_data'));
|
||||
51
vendor/niklasravnsborg/laravel-pdf/tests/PdfTest.php
vendored
Normal file
51
vendor/niklasravnsborg/laravel-pdf/tests/PdfTest.php
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace niklasravnsborg\LaravelPdf\Test;
|
||||
|
||||
use PDF;
|
||||
use Imagick;
|
||||
|
||||
class PdfTest extends TestCase
|
||||
{
|
||||
public function testSimplePdfIsCorrect()
|
||||
{
|
||||
$pdf = PDF::loadHTML('<p>This gets tested!</p>');
|
||||
$this->compareToSnapshot('simple', $pdf->output());
|
||||
}
|
||||
|
||||
public function testExposifyPdfExposeIsCorrect()
|
||||
{
|
||||
$pdf = PDF::loadFile('tests/views/exposify-expose.html');
|
||||
$this->compareToSnapshot('exposify', $pdf->output());
|
||||
}
|
||||
|
||||
protected function compareToSnapshot($snapshotId, $data)
|
||||
{
|
||||
$snapshotFile = "tests/snapshots/{$snapshotId}.pdf";
|
||||
|
||||
// create snapshot if it doesn't exist
|
||||
if (!file_exists($snapshotFile)) {
|
||||
file_put_contents($snapshotFile, $data);
|
||||
return;
|
||||
}
|
||||
|
||||
$snapshot = file_get_contents($snapshotFile);
|
||||
$this->assertPdfsLookTheSame($snapshot, $data);
|
||||
}
|
||||
|
||||
public function assertPdfsLookTheSame($pdf1, $pdf2, $message = '')
|
||||
{
|
||||
$assertedImagick = new Imagick();
|
||||
$assertedImagick->readImageBlob($pdf1);
|
||||
$assertedImagick->resetIterator();
|
||||
$assertedImagick = $assertedImagick->appendImages(true);
|
||||
$testImagick = new Imagick();
|
||||
$testImagick->readImageBlob($pdf2);
|
||||
$testImagick->resetIterator();
|
||||
$testImagick = $testImagick->appendImages(true);
|
||||
|
||||
$diff = $assertedImagick->compareImages($testImagick, 1);
|
||||
$pdfsLookTheSame = 0.0 == $diff[1];
|
||||
self::assertTrue($pdfsLookTheSame, 'Failed asserting that PDFs look the same.');
|
||||
}
|
||||
}
|
||||
31
vendor/niklasravnsborg/laravel-pdf/tests/TestCase.php
vendored
Normal file
31
vendor/niklasravnsborg/laravel-pdf/tests/TestCase.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace niklasravnsborg\LaravelPdf\Test;
|
||||
|
||||
use niklasravnsborg\LaravelPdf\Facades\Pdf;
|
||||
use niklasravnsborg\LaravelPdf\PdfServiceProvider;
|
||||
use Orchestra\Testbench\TestCase as OrchestraTestCase;
|
||||
|
||||
class TestCase extends OrchestraTestCase {
|
||||
/**
|
||||
* Load package service provider
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return lasselehtinen\MyPackage\MyPackageServiceProvider
|
||||
*/
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [PdfServiceProvider::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load package alias
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return array
|
||||
*/
|
||||
protected function getPackageAliases($app)
|
||||
{
|
||||
return [
|
||||
'PDF' => Pdf::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
BIN
vendor/niklasravnsborg/laravel-pdf/tests/snapshots/exposify.pdf
vendored
Normal file
BIN
vendor/niklasravnsborg/laravel-pdf/tests/snapshots/exposify.pdf
vendored
Normal file
Binary file not shown.
BIN
vendor/niklasravnsborg/laravel-pdf/tests/snapshots/simple.pdf
vendored
Normal file
BIN
vendor/niklasravnsborg/laravel-pdf/tests/snapshots/simple.pdf
vendored
Normal file
Binary file not shown.
245
vendor/niklasravnsborg/laravel-pdf/tests/views/exposify-expose.html
vendored
Normal file
245
vendor/niklasravnsborg/laravel-pdf/tests/views/exposify-expose.html
vendored
Normal file
@@ -0,0 +1,245 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Parkstraße</title>
|
||||
<style>
|
||||
@page {
|
||||
footer: page-footer;
|
||||
margin: 0;
|
||||
margin-top: 35pt;
|
||||
margin-bottom: 50pt;
|
||||
margin-footer: 18pt;
|
||||
}
|
||||
|
||||
@page :first {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: sans-serif;
|
||||
font-size: 12pt;
|
||||
}
|
||||
|
||||
table, tr, td {
|
||||
padding: 0;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table { width: 100%; }
|
||||
td { vertical-align: top; }
|
||||
|
||||
.page-break-before { page-break-before: always; }
|
||||
|
||||
.container { padding: 0 35pt; }
|
||||
|
||||
main .container {
|
||||
margin-top: 2em;
|
||||
}
|
||||
main h2 {
|
||||
margin: 0 0 .8em;
|
||||
page-break-after: avoid;
|
||||
}
|
||||
main p, main .table-wrapper {
|
||||
margin: 0 0 1em;
|
||||
}
|
||||
|
||||
.clearfix {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.text-center { text-align: center; }
|
||||
|
||||
.vertical-bar {
|
||||
display: block;
|
||||
width: 100px;
|
||||
border-bottom: 1px solid #ccc;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.col1 { width: 8.33333%; }
|
||||
.col2 { width: 16.66667%; }
|
||||
.col3 { width: 25%; }
|
||||
.col4 { width: 33.33333%; }
|
||||
.col5 { width: 41.66667%; }
|
||||
.col6 { width: 50%; }
|
||||
.col7 { width: 58.33333%; }
|
||||
.col8 { width: 66.66667%; }
|
||||
.col9 { width: 75%; }
|
||||
.col10 { width: 83.33333%; }
|
||||
.col11 { width: 91.66667%; }
|
||||
.col12 { width: 100%; }
|
||||
|
||||
#header {
|
||||
border: none;
|
||||
padding: 30pt 0;
|
||||
background-color: #3456D8;
|
||||
}
|
||||
|
||||
#header table {
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.grid-images {
|
||||
margin: -1%;
|
||||
}
|
||||
|
||||
.tile-image {
|
||||
float: left;
|
||||
padding: 1%;
|
||||
}
|
||||
|
||||
.tile-image img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.details-column-table {
|
||||
margin: 0 15pt;
|
||||
table-layout: fixed;
|
||||
}
|
||||
|
||||
.details-column-table tr {
|
||||
border: none;
|
||||
border-bottom: .5pt solid #ddd;
|
||||
}
|
||||
|
||||
.details-column-table tr:last-child {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.details-column-table td {
|
||||
line-height: 30pt;
|
||||
}
|
||||
|
||||
.details-column-table .label {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.details-column-table .value {
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.tag {
|
||||
float: left;
|
||||
width: auto;
|
||||
margin: 0 .5em .5em;
|
||||
padding: .3em .5em;
|
||||
background-color: #eee;
|
||||
border-radius: 3px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.contact-box {
|
||||
width: 350pt;
|
||||
margin: 35pt auto;
|
||||
padding: 30pt;
|
||||
border-radius: 2pt;
|
||||
border: 1pt solid rgba(0, 0, 0, .1);
|
||||
border-bottom-width: 3pt;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
.contact-image {
|
||||
margin: 0 auto;
|
||||
width: 30%;
|
||||
padding-bottom: 30%;
|
||||
border-radius: 50%;
|
||||
background-size: 100% auto;
|
||||
background-position: center;
|
||||
background-image: url(https://dummyimage.com/150x150);
|
||||
}
|
||||
|
||||
.contact-details {
|
||||
margin: 0 auto;
|
||||
width: 70%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.contact-name {
|
||||
margin-top: 18pt;
|
||||
margin-bottom: 0;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.contact-email {
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
.contact-phone {
|
||||
margin-top: 15pt;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header id="header">
|
||||
<div class="container">
|
||||
<div class="table-wrapper">
|
||||
<table>
|
||||
<tr>
|
||||
<td class="col9">
|
||||
<h1 style="font-size: 1.6em; margin-bottom: 10pt;">Parkstraße</h1>
|
||||
<div style="margin-top: 30pt;">
|
||||
Test
|
||||
</div>
|
||||
</td>
|
||||
<td class="col3" style="text-align: right; vertical-align: middle;"><img alt="Test Team" src="https://dummyimage.com/600x400/3456D8" style="height: 70px;"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<main>
|
||||
<div class="container">
|
||||
<div class="grid-images">
|
||||
<div class="tile-image" style="width: 98%;"><img src="https://dummyimage.com/400x200"></div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<h2>Details</h2>
|
||||
<table style="margin: 0 -15pt;">
|
||||
<tr>
|
||||
<td class="col6">
|
||||
<table class="details-column-table">
|
||||
<tr>
|
||||
<td class="label">Typ:</td>
|
||||
<td class="value">Wohnung zur Miete</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td class="col6">
|
||||
<table class="details-column-table">
|
||||
<tr>
|
||||
<td class="label">Nummer:</td>
|
||||
<td class="value">#5865</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="tags">
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="page-break-before"></div>
|
||||
<div class="container">
|
||||
<div class="contact-box">
|
||||
<div class="contact-image"></div>
|
||||
<div class="contact-details">
|
||||
<h3 class="contact-name">Niklas</h3>
|
||||
<div class="contact-email">
|
||||
test@gmail.com
|
||||
</div>
|
||||
<div class="contact-phone">
|
||||
1234
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user