Dompdf - 如何将相同的 pdf 文件附加到两个不同的 php 文件模板中?
我需要将相同的 pdf 文件放置到两个不同的模板中。
但如果我像这样在两个文件中放置相同的代码,就会出现问题。
如果该代码仅位于其中一个文件中,则一切正常。
代码是
add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3);
function attach_terms_conditions_pdf_to_email ( $attachments , $id, $object ) {
$your_pdf_path = get_template_directory() . '/pdf-test.pdf';
$attachments[] = $your_pdf_path;
return $attachments;
}
require get_template_directory() . '/pdf-test.php';
require_once get_template_directory() . '/assets/dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
ob_start();
require(get_template_directory().'/pdf-test.php');
$content_pdf = ob_get_clean();
$dompdf->loadHtml( $content_pdf);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A3', 'portarait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$output = $dompdf->output();
file_put_contents(get_template_directory() . '/pdf-test.pdf', $output);
pdf 文件具有相同的内容,只需为用户和管理员发送即可。 我尝试复制该文件,将其命名为 pdf-test-admin.php 和 pdf-test-admin.pdf,但没有帮助。 我还尝试在主functions.php文件中要求该库,并在我需要的文件中仅调用新的Dompdf,但它根本不起作用。 我对这个库还是新手,找不到像我的任务这样的东西。 插件不会帮助我,因为我的 php 文件中的内容非常具体。我需要在 dompdf 上准确地执行此操作。
如何在两个地方正确调用呢?
I need to place the same file pdf to two different templates.
But if I place the same code in both files like that, it's bugging.
If that code is in only one of that files, all works fine.
The code is
add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3);
function attach_terms_conditions_pdf_to_email ( $attachments , $id, $object ) {
$your_pdf_path = get_template_directory() . '/pdf-test.pdf';
$attachments[] = $your_pdf_path;
return $attachments;
}
require get_template_directory() . '/pdf-test.php';
require_once get_template_directory() . '/assets/dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
ob_start();
require(get_template_directory().'/pdf-test.php');
$content_pdf = ob_get_clean();
$dompdf->loadHtml( $content_pdf);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A3', 'portarait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$output = $dompdf->output();
file_put_contents(get_template_directory() . '/pdf-test.pdf', $output);
The pdf-file has the same content, just has to be sent both for user and for admin.
I tried to copy the file, called it pdf-test-admin.php and pdf-test-admin.pdf, it didn't help.
I also tried to require the library in the main functions.php file, and to call only new Dompdf in files I needed, it did't work at all.
I'm still new with this library, can't find something like my task.
Plugins wouldn't help me, cause my content in php-file is very specific. I need to do it exactly on dompdf.
How to call it in two places correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论