dompdf从html文件中呈现错误的数据

时间:2013-12-20 06:01:35

标签: dompdf

dompdf正在渲染错误的数据 我使用dompdf从html文件

创建pdf
    $dompdf = new DOMPDF();
    $id = $GLOBALS['post']->ID;



    $head_html = '<!DOCTYPE html>';
    $head_html .= '<html>';
    $head_html .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
    $head_html .= '<head>';
    $head_html .= '<title>'.get_the_title($id).'</title>';
    $head_html .= '</head>';
    $head_html .= '<body>';

    $content = apply_filters('the_content', get_post_field('post_content', $id));
    $body_html = str_replace(']]>', ']]&gt;', $content);

    $footer_html  = '</body>';
    $footer_html .= '</html>';

    $html = $head_html.$body_html.$footer_html;



    $upload_dir = wp_upload_dir();



    // Save the body part to a variable
    $fileContent = $html;


    // Create the name of the file and the declare the directory and path
    $html_filename = $upload_dir['path'].'/temp_wp_ps2pdf.html';


    $fp = fopen($html_filename, "w");
    fwrite($fp, $fileContent);
    fclose($fp);


    $pdf_filename = get_the_title($id);
    $dompdf->load_html( $html_filename );
    $dompdf->render();
    $dompdf->stream( $pdf_filename.".pdf" );

我在acrobat中读取文件时出错

编辑 pdf文件时我知道该文件没有获取$ filecontent = $ html的数据 它得到了网站的小内容:

<!DOCTYPE html>
<!--[if IE 7]>
<html class="ie ie7" dir="rtl" lang="he-IL">
<![endif]-->
<!--[if IE 8]>
<html class="ie ie8" dir="rtl" lang="he-IL">
<![endif]-->
<!--[if !(IE 7) | !(IE 8)  ]><!-->
<html dir="rtl" lang="he-IL">
<!--<![endif]-->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>שלום עולם! | test</title>
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="http://192.185.196.202/~workprog/wp/xmlrpc.php">
<!--[if lt IE 9]>
<script src="http://192.185.196.202/~workprog/wp/wp-content/themes/twentythirteen/js/html5.js"></script>
<![endif]-->
<meta name='robots' content='noindex,nofollow' />
 <link rel="alternate" type="application/rss+xml" title="test &raquo; פיד‏" href="http://192.185.196.202/~workprog/wp/?feed=rss2" />
 <link rel="alternate" type="application/rss+xml" title="test &raquo; פיד תגובות‏" href="http://192.185.196.202/~workprog/wp/?feed=comments-rss2" />
 <link rel="alternate" type="application/rss+xml" tit

html文件 - temp_wp_ps2pdf.html的内容为:

<!DOCTYPE html><html><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><head><title>שלום עולם!</title></head><body><p>ברוכים הבאים לוורדפרס. זה הפוסט הראשון שלך. אפשר למחוק או לערוך אותו, ולהתחיל לכתוב.</p>
</body></html>
更改后

   $dompdf->load_html( $html_filename );

为:

   $dompdf->load_html_file( $html_filename );

我明白了:

Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'Permission denied on /home/workprog/public_html/wp/wp-content/uploads/2013/12/temp_wp_ps2pdf.html.' in /home/workprog/public_html/wp/wp-content/plugins/wp-post-to-pdf/dompdf/include/dompdf.cls.php:709 Stack trace: #0 /home/workprog/public_html/wp/wp-content/plugins/wp-post-to-pdf/WP-post-to-pdf.php(124): DOMPDF->load_html_file('/home/workprog/...') #1 [internal function]: WP_post_to_pdf_display_icon('<p>????????????...') #2 /home/workprog/public_html/wp/wp-includes/plugin.php(199): call_user_func_array('WP_post_to_pdf_...', Array) #3 /home/workprog/public_html/wp/wp-includes/post-template.php(166): apply_filters('the_content', '???????????? ??...') #4 /home/workprog/public_html/wp/wp-content/themes/twentythirteen/content.php(41): the_content('???????? ??????...') #5 /home/workprog/public_html/wp/wp-includes/template.php(443): require('/home/workprog/...') #6 /home/workprog/public_html/wp/wp-includes/template.php(417): load_template('/home/workprog/...', fals in /home/workprog/public_html/wp/wp-content/plugins/wp-post-to-pdf/dompdf/include/dompdf.cls.php on line 709

0 个答案:

没有答案