I’ll also give you another pretty good code to convert your wordpress page content in PDF.
I’m sure that some of you are interested on it !
so let’s take the previous code (in my previous post).
At the very top of your document past that :
(at the very top because FPDF, modify “Header();”, and they can not be even a “space” caracter before beginig the PDF document…)
<?php
ob_start();
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/libraries.wordpress.php');
$content = wp_get_page_content('page_id',6);;
if ( strtolower($_GET['mode'])=='pdf' )
{
$content = utf8_decode($content);
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/libraries.class.HTML2PDF.php');
$pdf = new HTML2PDF('P','A4','US');
$pdf->WriteHTML($content,'');
$pdf->Output();
}
else
{
?>
<html>
<body>...
<div><?=$content;?></div>
...</body>
</html>
<?php
}
?>
In the library file :
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/libraries.wordpress.php');
you have to past the previous function wp_get_page_content()
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/blog/wp-load.php' );
function wp_get_page_content( $type='page_id', $id=0 )
{
$_GET[$type] = (int)$id;
$wp_did_header = true;
wp();
if ( have_posts() )
{
while ( have_posts() )
{
the_post();
$content = get_the_content();
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
}
}
return ( $content!=NULL )?$content:'';
}
?>
You need the FPDF library and it’s Class extends HTML2PDF freely dowloadable @ :
https://html2pdf.spipu.net/telechargement.php
Now when you call your page in your favorite browser (and I’m prety sure it’s firefox), add the GET parameter mode=’PDF’
Test the result in real:
https://www.reversoform.com/cgv/
give you the normal customize page with wordpress content, (but you can not know it, as it’s not a blog)
and :
https://www.reversoform.com/cgv/?mode=pdf
give you a PDF parsed “on-the-fly” with wordpress content (backward editable, with picture and all…).
Hope you’ll enjoy it !
Brice Pissard