我使用mpdf创建pdf的示例编码是,(它工作正常)
<? require_once('../mpdf.php');
$mpdf = new mPDF();
$mpdf->WriteHTML('<p>Your first taste of creating PDF from HTML</p>');
$mpdf->Output();
exit;
?>
Run Code Online (Sandbox Code Playgroud)
我的示例编码发送电子邮件:
$em =//email address ;
$subject = //subject;
$message = //message;
mail($em, $subject, $message, "From: MyDomain Webmaster<admin@mydomain.com>\nX-Mailer: PHP/" . phpversion());
Run Code Online (Sandbox Code Playgroud)
我的问题是pdf已经创建并直接在浏览器中打开,如何将pdf文件作为电子邮件附件发送?
如果可能请帮我解释一下代码或者只是帮我提一些建议,我会自己编写代码.
谢谢!
我目前在使用 php 的应用程序上遇到错误。这是错误消息
Error - mPDF requires mb_string functions. Ensure that PHP is compiled with php_mbstring.dll enabled.
Run Code Online (Sandbox Code Playgroud)
我正在使用第三方库生成 pdf 文件(MPDF)。它在我的 loaclhost (windows) 上运行良好,但是当我们将其部署到 linux 服务器上时,它会抛出上述错误。
任何人都可以帮助我了解发生了什么以及我该如何解决它。我们的 Linux 服务器配置中似乎缺少 php_mbstring.dll。
我在将 mPDF 生成的 pdf 保存到特定文件夹时遇到问题。pdf 生成一切正常,只是我无法将其保存到本地文件夹。有人可以帮我解决这个问题吗?
我在我的Web应用程序中使用mPDF.
我必须在Mpdf的帮助下创建发票文档.所以html表有大量行(即:如果它存在单页)引发此错误:
警告:在11008行的MPDF56/mpdf.php中为foreach()提供的参数无效
我正在使用以下代码生成pdf:
require_once(MPDF_PATH);
$mpdf=new mPDF('c','A4','0','',2,2,2,2,1,1);
$stylesheet = file_get_contents(dirname(__FILE__).'/invoice_print.css');
$mpdf->WriteHTML($stylesheet,1);
$html .="";
$mpdf->WriteHTML($html);
$mpdf->Output("$fileName",'D');
Run Code Online (Sandbox Code Playgroud)
我在Mpdf的构造函数中尝试了/不带参数.我发现mpdf与前4个参数一起使用没有任何问题......
$mpdf=new mPDF('c','A4','0','')
Run Code Online (Sandbox Code Playgroud)
但是当我添加"边距"(即:5-8)参数时,会抛出上述错误.
有没有人有这个???
我尝试过使用mPDF 5.3和5.6
我在CodeIgniter中使用mPDF.
这是我的lib(pdf.php)
class pdf {
function pdf()
{
$CI = & get_instance();
log_message('Debug', 'mPDF class is loaded.');
}
function load($param=NULL)
{
include_once APPPATH.'/third_party/mpdf/mpdf.php';
if ($params == NULL)
{
$param = '"en-GB-x","A4","","",10,10,10,10,6,3,"L"';
}
return new mPDF($param);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器
$filename = 'qwerty';
//...
// As PDF creation takes a bit of memory, we're saving the created file in /downloads/reports/
$pdfFilePath = FCPATH."reports\\" . $filename . ".pdf";
//$data['page_title'] = 'Hello world'; // pass data to the view
for($i=0;$i>=0;$i++)
{
if(file_exists($pdfFilePath) == TRUE) …Run Code Online (Sandbox Code Playgroud) 我正在使用Zend Framework并使用mpdf创建PDF.
我试图使用fontawesome来表示一些文章,但字体真棒的字体下面没有正确呈现代码.
$stylesheet = file_get_contents("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css");
$stylesheet .= file_get_contents("https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css");
$this->mpdf->WriteHTML($stylesheet,1);
$this->mpdf->WriteHTML($html,2);
$this->mpdf->allow_charset_conversion = true;
$this->mpdf->charset_in = 'windows-1252';
$this->mpdf->Output();
Run Code Online (Sandbox Code Playgroud)
我在html中使用的代码
<span class="company-name"> name of the company</span>
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我使用此链接pdf yii2安装程序安装mpdf,这不起作用.
我的行动是:
public function actionReport() {
// get your HTML raw content without any layouts or scripts
$content = '<html><head></head><body><h1 class="kv-heading-1">hello</h1></body></html>';
// setup kartik\mpdf\Pdf component
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_CORE,
// A4 paper format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => $content,
// format content from your own css file if …Run Code Online (Sandbox Code Playgroud) 我正在使用mpdf来动态创建PDF文件,并且文件在浏览器中打开很好,但Adobe给了我一个错误:
Adobe Acrobat Reader DC无法打开"example-filename.pdf",因为它不是受支持的文件类型,或者因为文件已损坏(例如,它是作为电子邮件附件发送而未正确解码).
我查看了有关此问题的其他问题(另一个mpdf + adobe错误),并在文本编辑器中查看了pdf.我发现文件的第一部分看起来像这样:
<!DOCTYPE html>
<head>
<title>
CapstoneDB
</title>
%PDF-1.4
%âãÏÓ
Run Code Online (Sandbox Code Playgroud)
删除所有内容%PDF-1.4(包括选项卡)后,文件在Adobe中打开很好,这很好,除了我需要能够在Adobe中打开生成的pdf而不必每次都手动摆弄代码.
这是我的包装函数,用html和css调用mpdf:
include('../mpdf/mpdf.php');
function user_download_pdf($html, $css_file, $filename) {
$mpdf = new mPDF();
$stylesheet = file_get_contents($css_file);
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html,2);
$mpdf->Output($filename, "D");
}
Run Code Online (Sandbox Code Playgroud)
我从不向mpdf提供一个完整的html页面,通常只是一个h3和一个或多个表.也许我需要给MPDF整个HTML页面,其中包括<head>,<body>,等?有没有办法改变mpdf配置或我在php中调用mpdf的方式,可以摆脱pdf文件开头的html垃圾,这些文件正在解决所有问题?
在mPDF中是否可以将图像做成圆圈?环顾四周,找不到明确的答案。
对我来说,这个图像显示得很好,除了它是一个正方形而且应该使它变成一个圆形。
的CSS
img{
width: 150px;
height: 150px;
border-radius: 150px;
}
Run Code Online (Sandbox Code Playgroud)
的PHP
$inputPath = '../web_content/cool_cat.jpg';
<div class="profile_img">
<img src="'.$inputPath.'"/>
</div>
Run Code Online (Sandbox Code Playgroud) 我使用barryvdh/laravel-dompdf包在laravel中生成DOM PDF.通过使用只读模式呈现视图和HTML元素,它工作正常.但是,我正在尝试生成可填写/可编辑的PDF,以便用户可以输入详细信息,而无需在第三方编辑器工具中打开它.
下面是我用来生成带有barryvdh/laravel-dompdf包的PDF的代码片段.
$file = "Storage/pdf/document.pdf";
$data = array("foo" => "bar");
$view = view('pdf.document', $data);
\PDF::loadHTML($view)->setPaper('A4', 'portrait')->setWarnings(false)-save($file);
Run Code Online (Sandbox Code Playgroud)
我也尝试了mpdf niklasravnsborg/laravel-pdf包,但这也是在可读模式下打开.
$data = [
'foo' => 'bar'
];
$pdf = PDF::loadView('pdf.document', $data);
return $pdf->stream('document.pdf');
Run Code Online (Sandbox Code Playgroud)
如果我需要为此代码配置任何选项,请建议我.