dompdf, Store the Contents of a WordPress Page in a Variable

using WordPress 3.8, i included dompdf library to generate portfolio of my site, i tried in different ways but got no solution. here is my code i tried.

<?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");
}
?>

Not: when i echo $contents variable , it prints the data which is stored in it.like

Read More
$post = get_page($id);
$contents = apply_filters('the_content', $post->post_content); 

echo $contents;

die();

but not storing in $html variable convert in PDF.

thanks in advance.

Related posts

Leave a Reply

1 comment

  1. Try this steps

        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));
    

    And the config:
    (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");