使用WordPress 3.8,我包含dompdf库来生成我的网站的组合,我尝试了不同的方式但没有解决方案。这是我试过的代码。
<?php
require_once ('dompdf/dompdf_config.inc.php');
$id="80";
$post = get_page($id);
$contents = apply_filters('the_content', $post->post_content);
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>';
$html.= $contents;
$html .='</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("Dotcom Portfolio.pdf");
}
?>
不:当我回显$ contents变量时,它会打印存储在其中的数据。像
$post = get_page($id);
$contents = apply_filters('the_content', $post->post_content);
echo $contents;
die();
但不存储在$ html变量中的PDF转换。
提前感谢。
答案 0 :(得分:1)
尝试此步骤
ob_start();
include('./some_dynamic_page.php');
$content = ob_get_clean();
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($content);
$dompdf->set_paper('A4', 'portrait');
$dompdf->render();
$dompdf->stream("result.pdf", array("Attachment" => 0));
配置: (dompdf_config.custom.inc)
//define("DOMPDF_TEMP_DIR", "/tmp"); //define("DOMPDF_CHROOT", DOMPDF_DIR); define("DOMPDF_UNICODE_ENABLED", true); //define("DOMPDF_PDF_BACKEND", "PDFLib"); define("DOMPDF_DEFAULT_MEDIA_TYPE", "print"); define("DOMPDF_DEFAULT_PAPER_SIZE", "A4"); //define("DOMPDF_DEFAULT_FONT", "serif"); define("DOMPDF_DPI", 300); define("DOMPDF_ENABLE_PHP", true); define("DOMPDF_ENABLE_REMOTE", true); define("DOMPDF_ENABLE_CSS_FLOAT", true); //define("DOMPDF_ENABLE_JAVASCRIPT", false); //define("DEBUGPNG", true); //define("DEBUGKEEPTEMP", true); //define("DEBUGCSS", true); //define("DEBUG_LAYOUT", true); //define("DEBUG_LAYOUT_LINES", false); //define("DEBUG_LAYOUT_BLOCKS", false); //define("DEBUG_LAYOUT_INLINE", false); //define("DOMPDF_FONT_HEIGHT_RATIO", 1.0); //define("DEBUG_LAYOUT_PADDINGBOX", false); //define("DOMPDF_LOG_OUTPUT_FILE", DOMPDF_FONT_DIR."log.htm"); define("DOMPDF_ENABLE_HTML5PARSER", true); define("DOMPDF_ENABLE_FONTSUBSETTING", true); // DOMPDF authentication define("DOMPDF_ADMIN_USERNAME", "admin"); define("DOMPDF_ADMIN_PASSWORD", "anypassword");