I'm creating a formatted list of data from a MySQL database table and 'echoing' it to screen perfectly well. How do I instead send the output to a local default printer, with or without a printer popup?
There must be a simple answer to this but I can't find it anywhere. Any help much appreciated.
Bob
I've looked all over and can't find anything other than saving it as a file with fopen() and fwrite(). And that of course needs the user to choose a path to save it in and a separate print procedure. I just want the php script to send the output to the printer.
maybe use something like https://tcpdf.org/about/
It creates and display a PDF which almost all devices with a browser can print and even save.
Related
is there any possible way to not lose any content, when inserting an image into a filled pdf, i am using the fpdm.php script from here and works prettty good i might add. the pdfs i am using i pass them trough pdftk, as in pdftk.exe insert.pdf output output.pdf so they can be filled via php with out throwing errors
so my problem is this, i have a pdf template, which i use to fill it with an array passed from php, and output it to browser or server, and works ok, but when i try to insert an image into it, it inserts it, but loses all filled data, i need to retain that data. i cant use pdftk because im on a godaddy shared hosting plan, also setasign scripts works i know, but i am trying to find a way without buying anything yet.
i found this stamper which stamps ok but loses pdf data, all boxes get blanked, and also this one that places the image and loses all data too. setasign is doing some magic stuff right there
All mentioned scripts are using FPDI in the background which simply doesn't modifes the original document but will allow you to recreate a completely new PDF document by importing another one page by page into reuseable structures (XObjects). Because form fields or other dynamic content like links or any other annotation type are not part of a pages content stream they will get lost.
The mentioned "magic" of the SetaPDF products is, that they modify the original document. Because of this all content will retain.
I have a PHP script with HTML forms for user to pick several things, after that it communicates with database and prints out the result in the form of a table. Everything is formatted with CSS.
Now I would like to make those results also saved in an xls file, ideally using some sort of a "Save file" button appearing after the script finish its work. For that to work though I have to use PHPExcel write commands in several different parts of the script. But those parts are also responsible for the output on the website.
I have tried using PEAR and recently also PHPExcel and I think I can make it work with saving the file on the server, but I couldn't do it with sending to browser option (so popping up message with 'Save file as...'). When I try to do it that way, it prints out all kinds of gibberish signs on the website and doesn't pop up with save file option at all. I found out this is because I am printing and echoing all sort of things in between the PHPExcel write commands, but I am not sure how to do it differently.
So I guess my question is: Is it possible in PHPExcel or any other library to use its write commands all over the PHP script with all sort of echos and HTML code in between while using the send to browser option?
Thanks you in advance for answers and help.
I am creating an .rtf file based on user submitted form for php web application. Until here it's fine.
Now I need to print this .rtf file on client side default printer silently without any rtf tags in it(print rtf file directly as it is as we have, when we open .rtf in MS-Word).
So is there any script, using javascript or jQuery to do this? Showing the printer dialog also works for me.
Can anyone please suggest me with examples. Thanks in advance.
This would require your script to reach outside of the browser sandbox and script the application to initiate printing, so it can not be done just using javascript and jQuery.
There are few approaches that might work:
First, if you converted the RTF to HTML unsing unoconv, and then called print via javascript, that would allow you to print from the browser, but it would probably include the browser's default headers and footers.
Second, but only for an Intranet application, you could lower the security settings for ActiveX from the Intranet zone, and run Word as an ActiveX control:
var msw = new ActiveXObject("Word.Application");
Third, again for an Intranet, have the server run OpenOffice and print to the network printer nearest the user.
Consider the use case and whether automatic printing adds enough value for the end users to be worth the extra hassle. Most of the things I "print" from the web, I actually just print to PDF and archive to disk, and most print dialog boxes require a few extra mouse clicks before sending the job to the printer anyway.
Anyone know any Javascript or PHP function to generate PDF and print (printer) automatically.
Excuse my ignorance, I searched on google about it and can not find sufficient documentation.
Many many Thanks Guys
What are you generating your PDF from? I presume that what you want to do is generate a PDF from e.g. a form submission, then print it on the user's computer?
You cannot print from PHP (well there are horrible ways of doing it, but don't) but I doubt it would help you even if you could - it would be printed on the server side, and I imagine you would be wanting to print on the client (i.e. browser) computer.
You can generate PDF's in PHP (have a look at FPDF) and send them to the browser, and you can print a web page in javascript, but to combine the two would be tricky, if it is possible at all. You certainly can't do it without prompting the user.
If you were to generate the PDF, then open it in an iframe, you could maybe call something through javascript to prompt the user with the standard printing options dialog, but that would be as far as it goes. It wouldn't work everywhere, if it worked anywhere, which I somehow doubt.
to create PDFs, theres the great FPDF-library.
printing automatically fortunately isn't possible - just imagine this would be possible and every f***g website could (in addition to the annoying popups and stuff) print out something (advertisements most of the time) on your printer.
EDIT :
if you have control over the clients, you could write a little batch-script like (not tested)
AcroRd32.exe /t %1 printername
and then set pdf-files in your browser to open automatically with this "programm" wich should then print the file without a print-dialogue.
note that you need access to the clients for this and it isn't tested. in theory this works: i did something very similar once to print out labels directly from the browser, but this was a few years ago using WinXP, don't know if this still works on Win7 (or whatever you're using).
I just want to know if it's possible. How do I save an html page and all of its contents to a database? like for example, I have a database wherein it consists all HTML pages.
Just want to know if its possible. And how to retrieve it too. We're using PHP as our language.
Thank you.
Well, you'll need to:
Grab that page by using a HTTP request, just like your browser does
Parse that HTML to find external resources (script, img, object, etc)
Grab those external resources
Save all them on your database into a BLOB field
Optionally alter your original HTML document, to change that resources location
Is this what you are trying to do? http://www.phpfreaks.com/forums/index.php?topic=219271.0
You can simply store the $out in the db instead of saving as html
Assuming MySQL, here is the way to connect to the database and write data into it.
PHP and MySQL
HTML is just text. You can tore it in a database in a TEXT field.
There are plenty of DBMS you can use and plenty of ways to do it.
You can have a look at the PDO extension to directly consume a MySQL or SQlite connection for instance.
You can also use an ORM like Doctrine
If you are trying to save the final results of your PHP script (ie. what is sent to the browser) you will need to look into Output Buffering.
As others already suggested, yes its possible to save HTML pages inside databases like mysql or sqlite etc. Another way you can perceive "databases" is flat files. Therefore, just like web crawlers or tools like wget/curl that crawls(and download) pages to disk, you can program something like that in PHP (using libraries such as curl) and save those pages to your disk. How to retrieve?? just display them with web browser OR do normal opening of file , display the contents and closing the file, all with PHP.