【发布时间】:2021-02-03 17:18:54
【问题描述】:
控制器
use PDF;
class PdfController extends Controller
{
public function index(){
return view('pdf/web',compact('data'))
}
public function generate(){
$pdf = \App::make('dompdf.wrapper');
$pdf -> loadView('pdf/web',compact('data'));
return $pdf->stream();
}
}
web.blade.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="charset=utf-8" />
<meta charset="UTF-8">
<title>100001</title>
<style type="text/css">
@page {
size: A4;
margin-top:0.5cm;
margin-bottom:0;
margin-left:0;
margin-right:0;
padding: 0;
}
.firstdiv{
display: flex;
flex-direction: column;
text-align: center;
justify-content: center;
align-items: center;
font-family: Cambria, Georgia, serif;
position: relative;
margin: auto;
width: 1200px;
height: 900px;
background-image: url("/img/bgimg.png");
background-repeat: no-repeat;
background-size: 100% 100%;
}
</style>
</head>
<body>
<div class="firstdiv">
#CONTENTS
#CONTENTS
#CONTENTS
#CONTENTS
</div>
我面临两种类型的问题
- 当我打开网页时,一切正常。对于 dompdf,背景图像未显示在 pdf 文件中。如需更多许可:我正在尝试查看网页并从中创建 pdf。当我使用控制器的索引功能打开网页时。我设计的一切都运行良好。但 pdf 文件仅以内容打开,不显示背景图片。
- 我的设计宽度为 1000 像素,高度为 630 像素。所以我想要横向模式的PDF。但是 pdf 以纵向模式出现。该部分的其余部分显示 pdf 中的空白。
【问题讨论】:
标签: php html laravel laravel-6 dompdf