anirban1087 0 Junior Poster in Training

Hi, I would like to take a printout from my system, after the user give some input. But I don't like to take printout of the form, I just like to have the form data in some other format. How to do that? I am using PHP & MySQL for my project.

Dani AI

Generated

For : two practical ways to get a clean printout of form data without printing the form itself — a client-side "print view" and a server-side PDF. The client-side approach renders a dedicated, minimal HTML page (either by redirect after submit or by opening a new window) and uses a print stylesheet via @media print plus a call to window.print(). That is quick and keeps output flowable in the browser; see MDN for details on print media and the print API (, Window.print()).

A simple printable page pattern (sanitize data before echoing) looks like this:

<?php
echo " ";
?>

<?php
// fetch $data from $_POST or DB; always sanitize output
$title = htmlspecialchars($data['title']);
$desc = htmlspecialchars($data['description']);
?>
<!doctype html>
<html>
<head>
<style>
@media print {
.no-print { display: none; }
body { font-family: Arial, sans-serif; font-size:12pt; }
}
@page { size: A4; margin: 10mm; }
</style>
</head>
<body onload="window.print()">
<div class="no-print"><button onclick="window.print()">Print</button></div>
<h1><?php echo $title; ?></h1>
<p><?php echo $desc; ?></p>
</body>
</html>

For consistent, downloadable output consider server-side PDF generation (Dompdf, TCPDF, mPDF). Dompdf converts HTML/CSS to PDF and can stream the file back to the browser; see the project page for install and usage (Dompdf). Notes: escape all user data to avoid XSS, implement access checks when fetching DB rows for printing, test page-break behavior (page-break-inside: avoid and @page rules) and raise PHP memory/time limits for large documents.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.