请帮助我,因为我无法在Laravel 5.2中创建PDF。
详细信息:
我的composer.json
文件
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"laravel/socialite": "^2.0",
"tzsk/payu": "^1.2",
"barryvdh/laravel-dompdf": "0.6.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
}
}
我尝试安装barryvdh/laravel-dompdf
运行后:此命令: -
composer require barryvdh/laravel-dompdf
结果:
使用版本0.6.1 for barryvdh / laravel-dompdf
./composer.json已更新
使用包信息加载composer存储库
更新依赖项(包括require-dev)
没有安装和更新
然后我尝试运行命令:composer update
,输出如下:
loading composer repositories with package information
updating dependencies (including require-dev)
nothing to installing and update
problem 1: this package require php>=5.5.9 but your PHP version (5.4.45) does not satisfy that require
答案 0 :(得分:0)
首先,您需要使用composer在项目中添加mPDF
通过终端或您的首选
composer require mpdf/mpdf
文档: - https://mpdf.github.io/
你可以像这样创建pdf
class PdfController extends Controller
{
// #example 1
public function createPdf($name = 'pdf'){
require_once '../vendor/mpdf/mpdf/mpdf.php';
$mpdf = new \mPDF();
$mpdf->WriteHTML(view('view.path..', ['data' => $data]));
$mpdf->Output($name.'.pdf','I'); // this will output data
}
// #example 2
// this will create fullpage pdf your can customize
public function createPdf($name = 'pdf', $html = ''){
require_once '../vendor/mpdf/mpdf/mpdf.php';
$mpdf = new \mPDF ('utf-8', 'Letter', 0, '', 0, 0, 0, 0, 0, 0);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
$mpdf->WriteHTML($html);
$mpdf->Output($name.'.pdf','I');
}
}