Reputation: 185
I have a problem with printing directly from php, and I don't want to use the window.print
because that's depending on the browser. So I am using this instead:
<!DOCTYPE html>
<html>
<body>
<textarea rows="5" cols="50">
<?php
$myfile = fopen("test.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
$file = file_get_contents('./test.txt', FILE_USE_INCLUDE_PATH);
echo $file;
$printer = printer_open("Adobe PDF");
if($ph = printer_open($printer))
{
// Get file contents
$fh = fopen("test.txt", "rb");
$content = fread($fh, filesize("test.txt"));
fclose($fh);
// Set print mode to RAW and send PDF to printer
printer_set_option($ph, PRINTER_MODE, "RAW");
printer_write($ph, $content);
printer_close($ph);
}
else "Couldn't connect...";
?>
?>
</textarea>
</body>
</html>
I have already added the php_printer.dll extention but I got the following error instead:
John Doe
Jane Doe
<br />
<b>Warning</b>: printer_open(): couldn't connect to the printer [Resource id #5] in <b>F:\LOKAL\text\text.php</b> on line <b>15</b><br />
?>
What's wrong with this? Thank you.
Upvotes: 0
Views: 2361
Reputation:
As I meaningfully can't comment, I write it here: I think you don't properly divide between client and server. JavaScript is running in the brower of the client, which make it possible to let the user print a document on his own printer. But PHP is completely server-side. So this would mean using the printer-functions, you can only print on devices connecting to the server. I don't think that this is what you want.
window.print() is supported by all important browsers, so I don't see a reason why you can't use it.
Upvotes: 0
Reputation: 102
this code.
$printer = printer_open("Adobe PDF");
Change to
$printer = "Adobe PDF";
Upvotes: 1