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.
Related
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.
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'm creating a php based web application which allows the user to upload a PDF file. This file will then be read and checked for certain data (text).
The problem is I can't figure out how to even open a PDF file in PHP. There are some PDF libraries mainly for creating PDF's, but they don't seem to be very good at reading them.
An alternative solution would be to use an already available solution in Python or something else (as described in other threads on this site) but I'd really like to stay as much as possible in PHP as I intend to later export the data to mysql, etc.
Any input on how to read a PDF and extract data from it would be much appreciated.
I personally haven't tried this out, but it looks like this one works: http://www.pdfparser.org/documentation
It's just a matter of downloading and telling your code to include it, just like the documentation shows.
Or you could try the class.pdf2text.php found in http://www.phpclasses.org/browse/file/31030.html
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 have spent a lot of time trying to get dompdf (http://www.digitaljunkies.ca/dompdf/) to work but I keep running into problems. I am trying to generate a PDF from a PHP script which generates a fairly complex, filled out web form. The script accepts a $_GET parameter (record number) and fills out the form accordingly with data from the database. I have no problem getting this data into the script as a string or any type of value really. What I am wondering is what the best approach would be for converting this type of data to a PDF?
The flow is as follows: user completes form and is taken to confirmation page which I would like to add a "Save as PDF" button. At this point one of two things could happen, the page that is currently being displayed in the browser could be spun directly to a pdf or a call to itself (scriptname.php?id=xyz) could be made using something like PHP's http_get() function and store the HTML as a string. From there I am having issues with preparing an accurate representation as a PDF.
I have heard some talk about fpdf but their examples don't really lead me to believe you can use dynamic data as the source, but please correct me if I am wrong about this.
Any input would be appreciated.
-- Nicholas
Well, I didn't know dompdf. Strange that it uses either a commercial library (PDFlib) or an outdated (?) one (CPDF, not updated for 3 years). But well, as long as it works (concept is interesting).
I don't understand what you mean by "use dynamic data as the source" (or rather, I see not point in generating static PDF!), but FPDF is used to generate various dynamic documents, like invoices in e-commerce products. I saw people using forks (like TCPDF) to handle Unicode data, though.
You can't transform an HTML page to PDF with FPDF, but you have a quite precise control of layout, using concept of cells with data.
You can see such kind of code there: http://svn.prestashop.com/trunk/classes/PDF.php
In the past when faced with this issue, I have used FPDF for the placement of data on a PDF template. Then, by setting the appropriate HTTP header, force the browser to pop open the Download / Save As box for the user to save said PDF.
In a class that extends FPDF/FPDI appropriately, use something like the following to generate a PDF from a template PDF you've already created (http://www.setasign.de/products/pdf-php-solutions/fpdi/):
$this->setSourceFile('pdf_template.pdf');
$template_page = $this->importPage(1, '/MediaBox');
$this->useTemplate($template_page, 0, 0);
Then, have FPDF generate the PDF for output using:
$this->Output();
You can also extend FPDF to accept (limited) HTML for formatting using the script found here: http://www.fpdf.org/en/script/script41.php