Javascript | Unable to get content of HTML while converting HTML page to PDF

Problem : Unable to get content of HTML while converting HTML page to PDF.

Solution : You can use the javascript if you want to get content of HTML while converting it into PDF :

<HTML>
<head>
<script type="text/javascript">
function submitForPDF()
{
document.getElementById("mybutton").style.visibility="hidden";
document.getElementById("hiddenbody").value = "<HTML><head></head><body>"+document.getElementById("htmbody").innerHTML+"</body></HTML>";
alert(document.getElementById("hiddenbody").value);

document.f1.submit();
alert("submitted");
}
</script>

</head>

PDF :

<?php
include 'mPDF60/mPDF.php';
ob_start(); // start output buffering
include 'newfile.php';
$content = $_POST['HTMLforPDF'];//ob_get_clean(); // get content of the buffer and clean the buffer
$mPDF = new mPDF();
$mPDF->SetDisplayMode('fullpage');
$mPDF->WriteHTML($content);
$mPDF->Output();
?>

Leave a Reply

Your email address will not be published. Required fields are marked *