<b>Suppose I have a customer details form, after fillup that form when I'll press <submit> it will redirect me to an another form where those details will be shown in a .doc format. I want to print this page...can any one plz HELP ME how can I do this job....plz post some CODE if available.........</b>

Dani AI

Generated

The thread shows two simple directions but misses practical trade-offs. asked for a printable page that looks like a Word document; correctly suggested that plain HTML is easiest when Word features are not needed, and pointed to client-side printing. The missing pieces are: how to deliver the printable file from PHP, how Word handles HTML-based .doc files, and reliable alternatives (real .docx or PDF).

A quick server-side export that many use (good for simple formatted text) is to send HTML with Word headers so the browser/Word treats it as a download. Example:

<?php
// render customer HTML then:
header('Content-Type: application/msword; charset=utf-8');
header('Content-Disposition: attachment; filename="customer.doc"');
echo $html; // $html contains the printable HTML for the customer
exit;
?>

Note: Word will open HTML-based .doc files but may warn and will not support modern .docx features. For genuine .docx generation use a library like PHPWord (https://github.com/PHPOffice/PHPWord) and consult the PHP header docs for correct headers (https://www.php.net/manual/en/function.header.php).

For consistent printed output across platforms, generating a PDF server-side is often better. Libraries to consider: Dompdf for direct HTML-to-PDF (https://github.com/dompdf/dompdf), wkhtmltopdf for full-webkit rendering (https://wkhtmltopdf.org), or TCPDF/FPDF for programmatic PDFs.

If the goal is to auto-print a separate page (as asked), render a dedicated printable page with a minimal stylesheet (use @media print) and either open it or redirect to it. The print page can trigger the print dialog on load:

<script>
window.addEventListener('load', function(){
  window.print();
});
</script>

Practical cautions: pass data via POST/session to avoid long GET strings; use absolute URLs for images; call header() before any output; be prepared for popup blockers when opening new windows; prefer PDF for faithful layouts and PHPWord for editable Word documents.

Recommended Answers

All 6 Replies

By .doc format you are meaning Microsoft Word? Or just a generic text document?

yes i mean MS Word.......plz help if possible

See if this helps:

and perhaps this:
http://conort.googlepages.com/generate-word-from-php

If you don't need any specific Word functionality, a simple text or html document would be the easiest.

okk that will also helpfull then how can i print HTML document ???????????

<A HREF="javascript:window.print()">Click to Print This Page</A>

if somebody have solution to print another page using javascript...

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.