Currently developing a partially dynamic page where I utilize GET functions to customize it and display the date in various places. At the end of this page, I want to include a button that allows visitors to download/open the page as a PDF without the header. Despite integrating DOMPDF, I am struggling to make it work correctly and need assistance. I have attempted solutions from Stackoverflow without success.
Essentially, I need the entire page printed in the PDF but not automatically open on load - only triggerable by the button click. Additionally, the header (specific div) should be excluded. Is this achievable?
<?php
require_once("dompdf/dompdf_config.inc.php");
$html =
'<html><body>'.
'<p>This is a test for '.
'<?php echo htmlentities(substr(urldecode($_SERVER["QUERY_STRING"]), 1)); ?> </p>'.
'<p>Thank you for reading.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("the_inquiry.pdf");
return true;
?>
<html>
<body>
<div class="shouldnotPrintToPDF">
Content.
</div>
<div class="shouldPrintToPDF">
Sensitive content.
<a href="the_inquiry.pdf">Open or save as PDF</a>
</div>
</body>
</html>
This serves as our one-page presentation containing substantial text. Therefore, I refrain from providing all details here. The challenge lies in duplicating the content in both $html = and within the actual HTML tag. Furthermore, the PDF saving option appears immediately upon page load, which is not intended. I also aim to add the echoed htmlentities part to the PDF name. Is this feasible? The PDF displays the contents set in $html = just fine but fails to respond to the link click.
Update: Following your guidance results in an error "The requested URL /inquiry.php&pdf=1 was not found on this server." Despite placing the target page intended for PDF printing at the root level and DOMPDF in /dompdf, the issue persists. Any insights on this?
Update: Upon adjusting the link, all information displays on a separate page as shown below.
{Information Display Error}
{More Information Display Error}
{Another Display Error causing frustration}
{Endless Errors with no solution}
Any thoughts on what could be causing this misinformation overload?
Breakthrough:
Enabling DOMPDF_DPI triggers the PDF opening action but causes all text to stack on the initial line of the second page, appearing jumbled. Furthermore, the inclusion of ?&pdf=1 in the htmlentities query string during PDF manifestation creates clutter. This undermines the personalization intent for both the page and PDF.