saint
saint

Reputation: 41

Print word files with PHP

I am using PHP to create a program to accept data from a form and then create 20 different DOC files which can be downloaded on click. I have done all this and if you click the usrl to 20 files, it gives pop up to save this files as word files. Now I am working on printing all these files using one click from the program itself without saving them. This data comes from DB so it is dynamic. Is it possible to print these word files using one click. Also some documents can have multiple copies.

Upvotes: 3

Views: 8043

Answers (2)

SAR
SAR

Reputation: 1845

One Top of your php or any html code

<?php
header("Content-Type: application/vnd.ms-word"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("content-disposition: attachment;filename=Report.doc");

?>

Upvotes: 0

Bence Gacs&#225;lyi
Bence Gacs&#225;lyi

Reputation: 296

You can't print Word files directly from browser unless user has a word processor extension for browser like Zotero. An other option is to convert your doc file to PDF, HTML or image format. wvWare is a software you can do this with. see: http://wvware.sourceforge.net/

To create word files with PHPWord. see: http://phpword.codeplex.com/

With this you can save your doc(x) files and add the links to your php page. Or you can directly download file when opening a PHP page by creating custom headers:

<?php
header('Content-Type: application/vnd.ms-word');
header('Content-Disposition: attachment;filename="myfile.docx"');
header('Cache-Control: max-age=0');

// Code that generates DOC

// output the file to the browser
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('php://output');
exit;
?>

See forum thread here: https://phpword.codeplex.com/discussions/225901

Upvotes: 1

Related Questions