I am converting a html table to pdf using php and fpdf,the problem is that for a table with large number of columns the data is going outside the pdf page.
Try TCPDF, it allow you to control every mm of page. It's well documented.
See the example n.11 for table or use it to write html inside pdf.
Related
I am working with a tool which lets user upload a .csv file.
That csv file contains an address column. I have to use the address from each row in another HTML template. That HTML template is like this
. After creating that template I then need to convert it into a PDF, store the PDF on a file server and give the user a link to the PDF.
I've finished the first two steps - csv upload and created complete template with address, but I'm stuck on how I can convert a template into a PDF.
I have looked into a few php-pdf libraries like fpdf mpdf. I'm facing a problem in creating pdf with html template.
A link to a library wich convert HTML to PDF and works pretty well.
First the link to the library
HTML2PDF
Then some code* to create your PDF using your own generated HTML, where $content is your HTML string.
$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML($content);
$html2pdf->Output('exemple.pdf');
*Code taken from the "example page" of the site.
I have used tcpdf in many cases, https://tcpdf.org/
Works well with tables, I have made receipts and accounting related stuff with it. Handle UTF-8 without problems, why it's my way to go.
Only downside is that code is bit long and complicated and it doesn't keep tables as tables in pdf and turns them to divs, so paddings and other styles might be bit trickier to do.
One way is to use webkit based HTML to PDF converter.
Pros are that it is easy to customize and style and to see in the browser how it will look and then you can be sure that it will look as same in PDF as well. You could use CSS and JavaScript as well to style and modify.
Cons are that it is hard to install it on the production server sometimes. But there are web services and APIs that get you covered.
For example one service is https://pdfapi.io. It is free to use. Only when your amounts get bigger, then it will charge like a cup of coffee.
Hope that helps.
I'm developing a small web application (using Apache-MySQL-PHP) that can display text and then transform it in PDF (the text is stored in a database as HTML code).
The problem is that the text I want to display and convert into PDF contains formulas...
The text displays correctly in web pages: I'm using MathJax that displays the formulas inside the math tag (currently in MathML code, but I can easily go for the LaTeX code) in the text.
Now I've to find a way to generate a PDF from the HTML-text that contains formulas...any clue?
Currently, I'm trying to convert HTML-text to PDF using FPDF and TCPDF (php classes) but they don't support the math tag (I didn't find one that does it... for free).
So, I'm trying to find a way to transform dynamically the formula in the math tag into an image (that I will save temporarily in the web server) and create the PDF using the formulas as images. In principle it should work, but at the moment I'm looking for a tool to convert the formula’s code to image and save it to the web server. Anyone know how to do that?
Thanks in advance!
I am extracting Rich Text data from MySQL and want to create a pdf from it. I am able to create a script where I have say only bold, italics, underlined one. It gets a much harder when the data has span tags with text color and background-colors, nesting of lists etc. Is there a way where pdf can be generated by just giving html page as an input? As the data contains tags.
creating PDF using php or any other language doesn't concern with your text format, its upto you will format your text and write on PDF.see THIS
Use MPDF to create your pdf page feom html
http://www.mpdf1.com/mpdf/index.php
you could use a third party HTML to PDF api like PDFCrowd
I've been using FPDF utility in order to export html output to pdf reoprt.
I'm successfully sending text and displaying it in the pdf file, but the problem comes up while trying to display real html structures- like tables and etc.In this case it seems like the encoding is not working well.
I've been trying to come up with a solution, but haven't had a success so far.
Any suggestions?
Thanks in advance
If you want to convert HTML to PDF in PHP you should have a look at MPDF. With FPDF you have to parse the HTML yourself, extracting paragraphs, formatting, images and tables and then need to call the FDPF functions for creating the elements in the PDF - you're basically rewriting MPDF functionality.
I have tried googleing this but can't seem to find an answer.
I have a client that has hundreds of PDF files, each of them have a form with any number of text-fields within them... it could range anywhere from 2 text-fields to 30 text-fields... that is an unknown.
What I need to do is read the PDF file, find all of the text-fields (including field names) within the PDF file so that I can dynamically generate a HTML form that an user will complete which then populates the PDF form.
How can I get a list of text fields and their names within a PDF document using PHP?
There are few tools to work on PDFs that are natively written in PHP.
You might however be able to run the pdftk binary to accomplish this task:
$fields = `pdftk input.pdf dump_data_fields`;
Not tried since I don't have a PDF with forms handy. But supposely you get a textual result list as described here: http://www.cs.unb.ca/~bremner/blog/posts/filling_in_forms_with_pdftk/