Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a database on phpmyadmin. Then I have a website with some products. When user clicks on a specific product, he gets some details about that product. Those details are pulled from the database.
My question is: Is it possible to create a pdf file with the specific details about that product, so the user can download it?
So, the options i know are:
DOMPDF : php class that wrap the html and build the pdf. Works good, customizable, based on pdflib, if i remember right it takes even some CSS. Bad news: slow when the html is big or many complex.
this is a tutorial to follow :http://www.sitepoint.com/convert-html-to-pdf-with-dompdf/
HTML2PS: same of DOMPDF, but this one convert first in .ps (ghostscript), then, in whatever format you need (pdf, jpg, png). For me is little better then dompdf, but have the same speed problem.. oh, better compatibility with css.
Those two are php classes, but if you can install some software on the server, and access it throught passthru() or system(), give a look to these too:
wkhtmltopdf: based on webkit (safari's wrapper), is really fast and powerfull.. seem like is the best one (atm) for convert on the fly html pages to pdf, taking only 2 seconds for a 3 pages xHTML document with CSS2. Is a recent project, anyway, the google.code page is often updated.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have written a REST application in laravel. It accepts a Json payload and creates a formatted pdf using this data.
Is it possible to write a test that checks the pdf has been generated correctly?
Edit:
Ideally I'd like to know the pdf is not corrupted, ie. Will open in a pdf reader.
Also it would be good to somehow check the content of the pdf. For example... does it contain the customers name?
Thanks.
Yes this is possible, given that the same JSON input always generates the same PDF.
You wouldn't really check the PDF file. PDF is a complex format, based on PostScript and some dark magic.
What you can do is generate a “sample” PDF once, then write a unit test that uses the same input data to generate a PDF file, then compare this to your sample.
This would look something like (just some example code):
$myPdf = $pdfGenerator->generatePdf();
$samplePdf = file_get_contents('/some/example/file.pdf');
// with PHPunit
$this->assertEquals(0, strcmp($myPdf, $samplePdf));
That's a bit dirty, but it does the job … if something in your PDF or JSON implementation changes, the unit test will make you aware of it.
It is important, however, that your PDF generator does not insert any “dynamic” data, such as date stamps. In that case, the PDF files could obviously never be identical.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I used dompdf to download a receipt that is initially in HTML format. But as soon as it gets converted, the orientation and the format gets distorted. Is there way to download an HTML page as pdf with the same height and width as the HTML page?
No there is not. Every html->pdf tool are different. some doesnt allow css some allow html5 but very bad. some allow gif etc. lots of variations. You shouldnt look for a tool that render the html page and convert to pdf. You should find something like view the page and get its screenshots of it and print as pdf. because today's complex html pages are just too overwhelming for html->pdf tools. Those tools are made for html coders to create fancy pdfs.
Try to search browser plug-ins. If you find one you can automatize the process via linux konsole. (fire-fox, maybe chrome too not sure though)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Does anyone have any ideas for what would be the best way to automaticly use someones online search database, given a static search (see example). It might also make this question more usefull to add a solution for a none static search.
So for example, I have a website and I wan't to create a link to the PDF file of the latest report by a certain person on this site: http://aris.empr.gov.bc.ca The search criteria does not change, all that changes is new results as the database is updated, so the search result is always http://aris.empr.gov.bc.ca/search.asp?mode=find Notice that not all entries have a report yet.
So far my idea is to use a php script to search through the source code of the completed search result page, search for the first instance of a .pdf string, and then extract the whole link (the page is orderd by date, so the first pdf file found would be the latest report that has a pdf file available.
The problems with this solutions:
1) it is very specific to my problem and only works for a static search result, and so is not a good Q&A
2) I am not sure if the completed search link researches everytime you follow it, or if it leads to an old result that could become out to of date
3) my solution is not sexy and is held together by duct tape, if you know what I mean.
Thanks,
-Adrian
In real terms you want to scrape the page(s).
You have 2 options in PHP:
1. Use CURL to fetch the page and USE PHP DOM parser to parse and extract the content from it.
2. You can use PHP Simple DOM Library, check here : http://simplehtmldom.sourceforge.net
It has ready made functions and you won't need to use CURL much here.
I hope you get an idea.
Try some code, show us here and we will guide more on this...
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
To generate pdf file from html page I have used libraries like MPDF , FPDF, DOMPDF etc.
In each pdf library I found following issues.
mpdf causes unnecessary page breaks
FPDF needs more writting. etc
When I used DOMPDF it worked fine but large table didn't expanded to next page and pdf broke without generating next pages.
Then I searched for another pdf library and I came to know about TCPDF.
SO I want to know what are the disadvantages of "TCPDF"?
A great alternative for PDF generation is wkhtmltopdf. It has a smooth integration and the result is awesome. You will have to install the binary into your server, though. If you're on a VPS or dedicated, this will not be a problem.
There's a PHP lib for using it, you can find it here: https://github.com/KnpLabs/snappy
Also, there's a nice solution for the large table problem you have. Maybe it can help you with another lib too, take a look here: https://code.google.com/p/wkhtmltopdf/issues/detail?id=566
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I've seen a couple of topics about this problem - The ability to print through a browser.
Unfortunately the only working solution for me was printing with an iframe.
the problem with iframe is that the browser actually hangs quite a bit when the page loads which is a good annoyance.
Is there any other way I can print a file? Should I display it as a html and print it or keep it pdf and use pdfjs to get it in canvas and print?
All of these though don't allow me to set print options, because I'm trying to send it to a label printer it requires specific dimensions.
Thanks in advance,
Sincerely,
The way I solved this is by installing wkhtmltopdf on my server. Since I use a dynamic page with Javascript to add content I send the whole html page to my php wich stores the html file in a temporary folder on my server and then I use wkhtmltopdf to create the pdf. Once thats done my ajax request opens op that new pdf file. and done you can print that pdf.
Its the best solution I found to print out with pdf files, the problem with other things is that you can't get rid of that extra clutter on the top and footer of the webpages.
Greetings
Ezeky
In the case of an HTML page :
as described here, you can specify css rules for the media type print in your css file. This will be applied when requesting for a print in your browser.