From last 6 hours trying best to show progress bar wile pdf is generated in TCPDF but not successful.
I am using TCPDF API for HTML to PDF generation, But the problem is that while generating the PDF we can't use custom javascript, Can we show progress bar while PDF is generated?
Any idea please?
I am not sure why you say "can't use custom javascript". If you just want a "loading icon" yoy should do this
- show loading icon (from js)
- ajax request to php file that generates the pdf into a server file
- on success you get a link to a generated pdf.
(for this solution you might try some estimation based on how large would be the generated file)
If you want an accurate progressive, you should add some estimation on php file. Let's say when you generate the pdf you know how many pages you will generate and each "addPage" command you save the status of completeness in a file or a memcached key. On you JavaScript side you call a file each second that reads that status of completeness.
No.
Even if you were able to use custom javascript, it would not be possible to get an accurate prediction of the time it will take to generate the document and therefore diplay progress - but it would be possible to get an estimate (based on extensive benchmarking). But in order to display the progress bar you'd need custom javascript and to change the processing to decouple the threads on the browser and server. This is discussed more in this question (which IMHO is not a duplicate of the post referenced).
Related
I have a HTML page that contains a table with a list of a customers orders (pulled from a database via PHP).
I want to have a button on the page that will allow the users to download a PDF copy excluding the navigation bar etc.
The examples that I've seen and tested online initially load the page in PDF format but I don't want this. I want it to load as it currently is but also have a button that when pressed downloads a PDF copy (i.e. not display it in the browser).
wkhtmltopdf will do the trick:
http://wkhtmltopdf.org/
It should allow you a lot of customization options.
But if you want to generate it dynamically then you have to use some library for pdf . There are many library like tcpdf, dompdf etc.
Dom pdf example
From experience I would recommend Phantom JS - see an example
I found Phantom JS offers better HTML/CSS support when compared to wkhtmltopdf.
Bear in mind, you will struggle to get support for things like CSS3 columns in Phantom and Wkhtmltopdf.
Workflow:
Land on initial page (later to be converted to PDF).
Display button - 'download as PDF'
Listen for the click event on this button and call a custom callback
function once the event is fired.
The callback function executes an Ajax call sending the full page
HTML as part of the server request.
On server side, fire up Phantom JS or Wkhtmltopdf to generate PDF. Save
PDF on server.
Generate URL for saved PDF and display/load client side.
PS; I'm not sure if Phantom JS will generate a PDF from a string or whether it expects a valid url. I know Wkhtmltopdf can generate a PDF from a string.
Hope this helps
Since you ask for the easiest way.. just print the HTML client side. This button invokes printing the web page client side:
<input type="button"
onClick="window.print()"
value="Print This Page"/>
Then the user would have to select a PDF printer driver. Chrome has this built in.
Here you can read how to exclude parts of the HTML (such as the print button itself) from being printed:
How do I hide an element when printing a web page?
I am currently working on a website which will be used for displaying scores in several benchmarks. In order to accomplish this, i am using PHP(duh :D) for the database queries and the JPGraph library, which creates the graph and then displays and it as an image with the GD library.
The user of the site can select which chart he wants to see with a <form> that contains the following criteria:
The Client that ran the test
The Operating System the Client used at the time
The Benchmark that was used
And what type of chart he wants to see (Bar graph, line graph....)
All of this works fine, the graph is displayed without a problem in the <iframe> that it is supposed to be in.
However, I also want the user to be able to save the Graph, with, say a second button. I can get the GD handle of the image, but how can I use this to save the image to a file on the client?
Any help would be very welcome.
Regards, Andy
I am using FPDF to create a pdf document in an iFrame... During the pdf creation the script communicates and gets a lot of data from the server, and then I would like to display a progress bar.. That is why I have put the php generator in an iFrame.. then my plan was that the php script could send the looped data to the parent window..
e.g. every time a loop is made it says $count++;, then I know how many loops it has gone through, and I already know that it is going to limit the rows to the first 200 rows.. Then I would like to display the looped data in the parent widow like so: $count of §goal has been generated successfully!.. At the moment I am using jQuery, where I ask the php to echo some jQuery script every time a loop is made to display the results like so window.parent.count($count, $goal);.. Count in the parent winodw and it actually works well until the PDF has to be shown.. then I get an error message that tells me that the script is unable to display the PDF because the page already has outputted data..
Does anybody know how to make the PHP to send the data to the parent window, so I prevet the using of echo?
Sorry for my bad english.. if wished I can try to upload my script later for you to see...
I do it a bit differently...
I also wrote an application in which the PDF generator needs to fetch a rather large amount of data, so the generation takes a few seconds.
I use jQuery to fetch a php-page in the background. During this download, the screen turns gray and displays a classic "please wait"-circle. The only output that the php-file generates is an "OK" echo, together with a file link, when the generation has been completed. Instead of displaying the file inline, I save the PDF in a folder ($pdf->Output('filename.pdf','S')) and offer it as a download using the provided link and the jQuery-callback.
I hope you understand what I mean. Maybe this thought will help you a bit further.
EDIT: Don't know if this will work, but I just thought of it...
You could save the file and output the filename. Using jQuery, you could then refresh the contents of the iframe to fetch a page in which you display the already saved PDF inline...
How could I use imagegrabscreen to get a thumbnail image and a full size image of a specific website.
I was thinking that I could have an array that I feed the wanted uri's into but I am a bit stuck on how I would set the wxh of the image I need to grab. I also think that I would need a thumbnail class and a fullimage class and call them when required.
Any better Ideas?
Keep in mind that imagaegrabscreen is Windows-only. If you have multiple displays set up, this function will only grab the primary display. Also, for this to work, your Apache service must be set to Allow service to interact with desktop otherwise you will just get a blank image.
This discussion covers the use of imagegrabscreen pretty well: Getting imagegrabscreen to work
There are a lot of other discussions about saving webpages as images, too - here are a few:
Website screenshots
Web Page Screenshots with PHP?
How can I generate a screenshot of a webpage using a server-side script?
PHP: How to capture browser window screen with php?
What is the best way to create a web page thumbnail?
Screenshot of current page using PHP
shell tool which renders web site including javascript
In any languages, Can I capture a webpage and save it image file? (no install, no activeX)
I have a "calculator" page that calculates a load of maths based on what the user inputs. The user can then click "get results" to show their full calculations.
I then have a button - "save as pdf" which I want it to allow the user to save a pdf of their results.
It's a combination of html, php, css combined with Wordpress.
How can I (on click) convert the results to a pdf and allow the user to save?
p.s I know this been asked a few times but I can't seem to find the correct answer or a working version... or a tool with good documentation for me to follow!
Check also FPDF
Generally these things are solved on the server. Clicking the link would trigger a redirect to the php page and in general instead of writing output to a webpage, you write output to a pdf stream (still arrives in the browser but the browser knows it as a pdf).
you do this by changing the response headers. you could use this library to write out the pdf file
http://code.google.com/p/wkhtmltopdf/ make sis pretty simple, you could do a curl request to the page, and send it to the library.