dompdf 相关问题

用PHP编写的HTML到PDF转换器

如何在 @page 中垂直居中 div 并打印(DomPDF 和 Laravel)

美好的一天!我目前正在使用 Laravel 8 的 DomPDF 库,使用本机 CSS 生成可打印的 PDF(因为 Bootstrap 和其他导入不能很好地与该库配合使用)。 我找到了...

回答 3 投票 0

DOMPDF PHP 库不添加辅助功能标签

我需要在 PHP 中以编程方式生成一个完全可访问的 PDF。 我尝试将 DOMPDF 与 Adobe 自动标记 REST API 结合使用。然而,这样一来,图像就会缺少“alt”文本和 PDF 我...

回答 1 投票 0

DOMPDF 不会更改生成的 PDF 中的字体

我尝试更改默认字体时遇到问题。 生成的 PDF 中的符号被 ??? 更改符号,所以我尝试更改默认字体。 但是当我尝试更改默认字体时...

回答 1 投票 0

如何使用 Dompdf 将 MySQL 数据库中的图像显示为 pdf

我尝试使用DomPDF在PDF中显示数据库中的图像后,它没有出现,并且加载速度很慢。 我的看法: 我尝试使用DomPDF以PDF格式显示数据库中的图像后,它没有出现,并且加载速度很慢。 我的看法: <div class="image"> <img src="{{ $logo }}" alt="Sample Image" style="height: 50px;"> </div> 我正在开发一个 Laravel 项目并使用 DomPDF 生成 PDF 证书。下面的代码来自我的CertificateController,它处理这些证书的生成: namespace App\Http\Controllers; use App\Models\Certificate; use App\Models\Term; use Illuminate\Http\Request; use PDF; use Auth; // Import the Auth facade use Barryvdh\DomPDF\PDF as DomPDFPDF; use Illuminate\Support\Facades\Auth as FacadesAuth; use Illuminate\Support\Facades\Storage; class CertificateController extends Controller { public function generateCertificate($termId) { // Fetch the term and relevant data $term = Term::find($termId); // Check if the term and necessary data are available // Get the authenticated user's name $userName = FacadesAuth::user()->name; $userLastName = FacadesAuth::user()->last_name; // Fetch the certificate data, including the logo URL $certificate = Certificate::first(); // Prepare data for the certificate template $data = [ 'username' => $userName, // Use the authenticated user's name 'userlastname' => $userLastName, 'course' => $term->course->title, // Assuming that 'course' is a property of the Term model 'term' => $term->title, // Assuming that 'title' is a property of the Term model 'date' => $term->finish_date, // Assuming that 'title' is a property of the Term model 'logo' => asset('storage/' . $certificate->logo), 'position_1' => $certificate->position_1, 'position_2' => $certificate->position_2, 'name_1' => $certificate->name_1, 'name_2' => $certificate->name_2, ]; // Load the certificate template HTML $html = view('certificate.certificate', $data)->render(); // Generate the PDF from the HTML $pdf = PDF::loadHTML($html); // Set the paper size to certificate size (e.g., A4) and landscape orientation $pdf->setPaper('Letter', 'landscape');; // Set the file name for the PDF $fileName = 'certificate_' . $term->id . '.pdf'; // Optionally, you can store the PDF on the server or force download // Example: $pdf->save(storage_path('certificates/' . $fileName)); // Example: return $pdf->download($fileName); // Display the PDF in the browser return $pdf->stream($fileName); } // Method to handle the form submission public function index() { $certificate = Certificate::first(); // Retrieve a single certificate return view('contents.admin.badges.index', compact('certificate')); } } 要在 Laravel 中使用 DomPDF 以 PDF 形式显示 MySQL 数据库中的图像,您可以按照以下步骤操作: 确保您已安装所需的软件包: DomPDF:作曲家需要 barryvdh/laravel-dompdf Laravel Collective HTML 包:composer require laravelcollective/html 确保您的数据库表包含用于存储图像数据的列。您可以使用 BLOB(二进制大对象)数据类型来存储图像。 在你的 Laravel Blade 视图(例如,certificate.blade.php)中,你可以使用 Laravel Collective HTML 包的 image 方法来显示图像。 这是您的证书控制器的更新代码: namespace App\Http\Controllers; use App\Models\Certificate; use App\Models\Term; use Illuminate\Http\Request; use PDF; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; class CertificateController extends Controller { public function generateCertificate($termId) { // Fetch the term and relevant data $term = Term::find($termId); // Check if the term and necessary data are available // Get the authenticated user's name $userName = Auth::user()->name; $userLastName = Auth::user()->last_name; // Fetch the certificate data, including the logo $certificate = Certificate::first(); // Prepare data for the certificate template $data = [ 'username' => $userName, 'userlastname' => $userLastName, 'course' => $term->course->title, 'term' => $term->title, 'date' => $term->finish_date, 'logo' => Storage::disk('public')->url($certificate->logo), // Use the Storage facade to get the URL 'position_1' => $certificate->position_1, 'position_2' => $certificate->position_2, 'name_1' => $certificate->name_1, 'name_2' => $certificate->name_2, ]; // Load the certificate template HTML $html = view('certificate.certificate', $data)->render(); // Generate the PDF from the HTML $pdf = PDF::loadHTML($html); // Set the paper size to certificate size (e.g., A4) and landscape orientation $pdf->setPaper('Letter', 'landscape'); // Set the file name for the PDF $fileName = 'certificate_' . $term->id . '.pdf'; // Optionally, you can store the PDF on the server or force download // Example: $pdf->save(storage_path('certificates/' . $fileName)); // Example: return $pdf->download($fileName); // Display the PDF in the browser return $pdf->stream($fileName); } // Method to handle the form submission public function index() { $certificate = Certificate::first(); // Retrieve a single certificate return view('contents.admin.badges.index', compact('certificate')); } }

回答 1 投票 0

使用 DOMpdf 在 Laravel 中生成包含图表的 PDF

我已成功创建图表,但我不知道如何在 pdf 中呈现此图表。我已经尝试了很多东西,但它不起作用。我使用“Laravel 图表”库创建了图表并使用...

回答 1 投票 0

使用 DOMPDF 和 WordPress 生成的 PDF 中不显示图像

我正在开发一个 WordPress 插件,我可以使用 DOMPDF 生成 PDF。生成过程有效,但我遇到了图像未显示在生成的 PDF 中的问题。 这里...

回答 1 投票 0

DOMPDF,收集填写的输入字段

我正在使用 DOMPDF 库生成 PDF,到目前为止一切顺利,但我收集的已完成表单字段未在 PDF 中收集和显示。我想知道我做错了什么,我会......

回答 1 投票 0

使用 Dompdf 保存 PDF 文件

使用Dompdf将数据存储在pdf文件中: 这个功能工作正常: $pdf = \App::make('dompdf.wrapper'); $pdf->loadHTML('Test '); 返回 $pdf->stream(); 现在,当尝试 $p...

回答 4 投票 0

Laravel、Livewire 和 DOMPDF

我有一个非常简单的 Livewire 组件: 我有一个非常简单的 Livewire 组件: <?php namespace App\Http\Livewire; use PDF; use Livewire\Component; use App\Models\Employee; class Employees extends Component{ public $employees; public function mount() { $this->employees = Employee::all()->toArray(); } public function createPDF() { $this->employees = Employee::all()->toArray(); // dd($this->employees); $pdf = PDF::loadView('livewire.employees', $this->employees); return $pdf->download('pdf_file.pdf'); } public function render() { return view('livewire.employees'); } } 还有一个非常简单的刀片文件,我在其中呈现单击按钮时要打印的员工姓名。 <div class="container mx-auto"> @foreach ($employees as $e) <h2>{{ $e['name'] }}</h2> @endforeach <button wire:click="createPDF" class="mt-8 bg-black text-white px-4 py-2 rounded">PDF</button> </div> 问题是我得到了 foreach 循环内的变量“未定义的变量 $employees”。 您没有在 PDF 调用中设置变量,因此该变量不存在。 简单改变 $pdf = PDF::loadView('livewire.employees', $this->employees); 到 $pdf = PDF::loadView('livewire.employees', ['employees' => $this->employees]); 附注我不太明白为什么每次单击 PDF 生成按钮时都会获取员工。您已经将其设置在安装中,因此它应该已经设置。每次重新获取都相当慢。

回答 1 投票 0

为什么我的 DomPDF 无法渲染 HTML 中的图像?

我正在 PDFGeneratorService 中制作 PDF,除了图像未渲染外,一切正常。我已将图像更改为jpeg格式,我已添加chroot,我已添加 'dompdf' =>[ ...

回答 1 投票 0

Dompdf while 循环 - 仅最后一条记录转换为 pdf

<?php require"../db_connection1.php";?> <?php require"../db_connection4.php";?> <?php require"../db_connection5.php";?> <?php require_once('../dompdf/autoload.inc.php') ; use Dompdf\Dompdf ; ob_start() ; if (isset($_POST["submit"])) { $payroll_date = mysqli_real_escape_string($connection5, $_POST["payroll_date"]) ; } $query = "SELECT * FROM ".$payroll_date." "; $result = mysqli_query($connection5, $query); while ($row1 = mysqli_fetch_array($result)) { $Employee_Number = $row1[0] ; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title></title> <link href="../bootstrap.min.css" rel="stylesheet"> <style type="text/css"> .SECTION-1 { margin-top:110px ; margin-left: 108px ; margin-bottom: 5px ; } </style> </head> <body> <form action = "#" method ="POST"> <div class ="SECTION-1" > <?php $query_hr_data = "SELECT * FROM applicants_final WHERE employee_number = '{$Employee_Number}' "; $result = mysqli_query($connection4, $query_hr_data ); while ($row5 = mysqli_fetch_array($result)) { $cost_center = $row5['cost_center'] ; $position = $row5['position'] ; $query = "SELECT * FROM ".$payroll_date." WHERE EE_NUMBER = '{$Employee_Number}' "; $result = mysqli_query($connection5, $query); while ($row1 = mysqli_fetch_array($result)) { $EE_NUMBER = $row1['EE_NUMBER'] ; $EE_NAME = $row1['EE_NAME'] ; $query2 = "SELECT * FROM ".$payroll_date." WHERE EE_NUMBER = '{$Employee_Number}' "; $result = mysqli_query($connection1, $query); while ($row2 = mysqli_fetch_array($result)) { $LATES_UNDERTIME_HRS = $row2['LATES_UNDERTIME'] ; $ABSENCES_HRS = $row2['ABSENCES'] ; echo "<table id ='heading'>" ; echo"<tr>" ; echo"<th id ='heading-2-1'>EE Name </th>" ; echo"<td id ='heading-2'>" .$row1['EE_NAME']." </br> </td>" ; echo"<th id ='heading-2-1'>Philhealth # </th>" ; echo"<td id ='heading-2'>" .$philhealth_number." </br> </td>" ; echo"</tr>" ; echo"<tr>" ; echo"<th id ='heading-2-1'>Basic_Salary </th>" ; echo"<td id ='heading-2'>" .number_format($basic_salary,2). "</br> </td>" ; echo"<th id ='heading-2-1'> Allowances </th>" ; echo"<td id ='heading-2'>" .number_format($deminimis_benefits,2)."</br> </td>" ; echo"</tr>" ; echo "</table>" ; echo "<table id='design-8'>" ; echo"<tr>" ; echo"<th>Lates_Undertime ( minutes ) </th>" ; echo"<td>" .$LATES_UNDERTIME_HRS. "</br> </td>" ; echo"<td>" .$LATES_UNDERTIME." </br> </td>" ; echo"</tr>" ; echo"<tr>" ; echo"<th>Absences </th>" ; echo"<td>" .$ABSENCES_HRS." </br> </td>" ; echo"<td>" .$ABSENCES." </br> </td>" ; echo"</tr>" ; echo "</table>" ; echo "<div id='design-2'> *** Payslip Confidential *** </div>" ; ?> </form> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> </body> </html> <?php $html = ob_get_clean(); $dompdf = new Dompdf(); $dompdf->load_html($html); $dompdf->setPaper(array(0, 0, 612, 1100), 'portrait'); $dompdf->render(); $pdf = $dompdf->output(); $file_location = "C:/wamp/www/dbs-program/payroll-program/version-3.4/pdfReports/".$Employee_Number.".pdf" ; file_put_contents($file_location, $pdf); } } } ?> 谢谢布莱恩,我更新了代码,我只是删除了冗余数据,这样就可以了 不要太长。再次感谢您再次查看。 我想打印 50 多个 pdf 并将其保存到指定文件夹,pdf 名称为员工编号,来自 mysql数据库。现在的问题只是 while 循环中的最后一个数据正在被 转换为pdf,如果我将第一个查询的右括号转移到 html后的最后一个代码,转换后的pdf只是第一个。当我 echo $Employee_Number = $row1[0] 我得到了所有 50 多个数据。我已经尝试过了 迭代,例如 for,但它变得更复杂,因为它打印出来 pdf 的确切数量,但没有打印任何数据,希望有人 有关如何继续的帮助或提示。先谢谢你了。 I also have a similar problem.only the last record in the database gets converted into pdf.anyone to help. <?php `require_once('./dompdf/dompdf/autoload.inc.php'); include('connect.php'); use Dompdf\Dompdf;` `$sql ="SELECT fname,lname FROM worker"; $results= mysqli_query($conn,$sql); while($row=mysqli_fetch_assoc($results)){ $fname=$row['fname']; $lname=$row['lname']; $i=1; $html=''; $html .=' <table border="1" cellspacing="0"style="width:100%; text-align:center" > <tr> <th>#</th> <th>FIRST NAME</th> <th>LAST NAME</th> </tr> <tr> <td >'.$i.'</td> <td> '.$fname.'</td> <td>'.$lname.'</td> </tr> </table> '; $i++; } $dompdf= new dompdf(); $dompdf->loadhtml($html); $dompdf->setPaper('A4','landscape'); $dompdf->render(); $dompdf->stream("liseli",array("Attachment"=>0));` ?>

回答 1 投票 0

使用 DOMPDF 禁用复制和粘贴

有没有办法禁用 PHP 中使用 DOMPDF 生成的文档的复制和粘贴? 我喜欢在我的网站中生成 pdf,并且还喜欢防止用户复制和粘贴内容。是...

回答 1 投票 0

如何使用dompdf设置pdf的自定义宽度和高度?

当我使用 dompdf 创建 pdf 时,它会将其生成为默认宽度和高度。我想设置我创建的 pdf 的自定义宽度和高度。如果在 dompdf 中不可能,请建议其他一些

回答 2 投票 0

使用 PHP DOMPDF 和 AJAX 下载 PDF 文件

我有一个名为 print.php 的 PHP 文件: 加载_...

回答 3 投票 0

Dompdf 无法显示图像

此代码将 HTML 转换为 PDF。 生成 PDF 时,图像不会出现,并显示错误,指出“未找到图像或类型未知”。我该如何解决这个问题?我已经实现了这个...

回答 1 投票 0

dompdf 对页面进行编号,但跳过第一页

我使用 dompdf 类,我需要每个页面的页码编号 我这样做了并且有效: $dompdf = new Dompdf(); $dompdf->load_html($html); $dompdf->render(); $canvas = $dompdf->get_can...

回答 4 投票 0

在laravel中使用DomPDF将数据导出为pdf时第二列被拉伸

我在 Laravel 项目中使用 DomPDF。它打印得很好,但它拉伸了第二列图像。我需要两列占据一半的可用空间。我将在以后分享我的代码。 CSS F...

回答 1 投票 0

Laravel livewire DOM PDF 文件保存但未下载

我正在使用DOM PDF打印html发票页面,该方法通过livewire方法调用,文件正确保存到公共文件夹,但我需要通过浏览器下载它而不是保存它。 通讯...

回答 3 投票 0

Dompdf 默认页眉内容重叠

我在从 dompdf 创建 pdf 时遇到小问题。在html页面标题位置:固定内容重叠在页面标题上。页面内容是动态加载的。如何清除

回答 2 投票 0

使用 dompdf 和 php 的 pdf 报告中出现混乱的卡纳达语字体

[ಹೌದುಯಾರಲ್ಲಿ在从 dompdf 渲染时应该像这样显示。 这是我的代码..我使用了 noto sans kannada 常规字体 ](https://i.stack.imgur.com/ADeiA.png) ಹೌದು ಯಾರಲ್ಲಿ 文字秀...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.