• Haja

    (@hajakutbudeen)


    Hello there,

    I want to convert html template into pdf, for that i need dompdf.

    I download that from github (https://github.com/dompdf/dompdf/releases/download/v2.0.0/dompdf_2-0-0.zip) extract that and upload into child theme section.

    In functions.php added following code for testing

    add_action( 'wp_footer', 'temp' );
    function temp(){
    	include_once( get_stylesheet_directory() .'/dompdf/autoload.inc.php');
    	use Dompdf\Dompdf;
    	define('DOMPDF_UNICODE_ENABLED', true);
    	$dompdf = new Dompdf();
    	$dompdf->load_html("<h1>Hello World</h1><p>PDF description</p>");
    	$dompdf->setPaper('A4','potrait');
    	$dompdf->render();
    	$dompdf->stream('title.pdf');
    }

    When i reload my page its shown error There has been a critical error on this website.

    please advise.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    If you’re able to rename the HTML file with a .pdf extension, you don’t really need dompdf. But you may use it if you prefer.

    Anyway, when you get that critical error message, you need to check your server’s error log to learn what the actual error was so you can take corrective action.

    While you’re developing new code, it’s a minor hassle to check the log every time any error is introduced. (I tend to make a lot of errors). I like to define WP_DEBUG as true in wp-config.php. Right below that definition, add this line:
    define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );
    With those changes, error messages will appear right on the page, no need to go looking for the error log. Don’t leave things this way on a production site (set both to false for production), visible error messages can be leveraged by hackers to gain useful knowledge about your site.

    Thread Starter Haja

    (@hajakutbudeen)

    Hey,

    Actually i want convert customer invoice email to pdf thats why i need dompdf lib, i added those lines in wp-config which is you mentioned, there’s not error highlighted, i checked server side error cause on code

    use Dompdf\Dompdf;

    so there’s no error in first line include_once( get_stylesheet_directory() .’/dompdf/autoload.inc.php’); next line trigger issue

    Moderator bcworkz

    (@bcworkz)

    Namespace declarations must be the very first thing in a PHP file, right after the initial <?php. Your dompdf code needs to be in its own file, which you can then include or require from elsewhere.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘dompdf integration’ is closed to new replies.