Create PDF in PHP without manually creating HTML - php

Can we really generate pdf files using php thro' some APIs without manually creating HTML. Beacuse I have got to create Invoices for some 50 groups and each having different HTML, so it would be a pain to create HTML for each of them and then create PDF using library from this HTML. Is there any other way?

yes of course, start learning from
http://www.fpdf.org/ or
https://tcpdf.org/
It will definitely helps you

Related

php - generate pdf with html table and save it on file server

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.

Send invoice PDF convert

I am making an app that creates an invoice.
It is created in HTML and PHP using different data from a database.
I need to create a function that converts the page into a PDF and send it to a client.
I can not store it on server as it would mean to create a few hundred everyday. I need something like "http://FreeHTMLtoPDF.com/?convert=".$strBillURL; but it's not working any more.
Many thanks if you can help me!
I prefer to generate PDF files using some library that converts HTML/CSS to PDF. One of the libraries that provides this and is very easy to use is mPDF:
https://github.com/mpdf/mpdf
I have no information regarding what type of PDFs you generate, but in my projects I tend to generate them on the fly from the data in the database and do not store them at all.
There are also other options available for converting HTML to PDF, like wkhtmltopdf, but they might require additional knowledge in set up: https://github.com/wkhtmltopdf/wkhtmltopdf

PHP PDF conversion

I am using PHP 5.0 pdf library to convert files dynamically into PDF.
I am using this reference from the official PHP website using PDF_new(), creating its object and using PDF_set_info and PDF_get_buffer functions.
This works fine, but when I want to create PDF pages and writing the content inside of it, there is no reference given anywhere on how to convert an already existing page to PDF. Say a page in my folder bill.php with CSS too needs to be converted to PDF on the fly.
Well converting HTML to PDF is not that easy, there are several libraries out there that might fit your needs. But none has full html/css capabilities, especially not css3.
FPDF
http://www.fpdf.org
TCPDF
http://www.tcpdf.org
DOMPDF
http://code.google.com/p/dompdf/ (this class allows you to easily convert simple layouted websites to pdf. i used this class quite often with almost no problems. sadly this library does not support converting of forms to usable input fields.)
WKHTMLTOPDF
http://code.google.com/p/wkhtmltopdf/ (actually a linux package but php wrappers are existing. this gives almost full html capabilities and awesome results)
html2PDF is a nice library to use. Make sure you change the default language to English though. I've used it many times to create dynamic invoices with tables and divs. Works really well.
Refer some of the articles, which may help to improve your knowledge as well as clear some of doubt of you.
Getting started
Convert HTML To PDF in PHP The Easy Way
How to Generate a PDF With PHP
Convert HTML to PDF
This HTML to PDF SDK may also help you.
Hope, it will help you.

Create PDF pages in PHP

Which is the best PHP-PDF library that can be used to create PDF files with more than 100 pages?
I am creating an application where there is need of creating PDF reports of account for an entire financial year, which library should is use?
See here:
Converting HTML to PDF using PHP?
Which one is the best PDF-API for PHP?
HTML to PDF vs. Programmatically creating PDF via PHP
Converting HTML to PDF (not PDF to HTML) using PHP
Specifically: https://stackoverflow.com/search?q=php%20pdf
Use tcpdf library. It might be best for you.

Creating PDF's using PHP

What I am wanting to do is create a PDF ideally from HTML code. I found a class called dompdf but I'm having issues with font and page breaks.
Does anyone know of another script or even a better way in general to generate PDF files?
The reason why I am converting HTML to PDF is because I want someone to use a WYSIWYG editor to create the contents and click save to generate their PDF file...
Any input would be greatly apprecaited
Due to the different nature of PDF and HTML you'll always have to make a few comprimises when trying to convert HTML into PDF.
If this doesn't bother you too much, I'd get started with TCPDF. Its easy to use and has a fairly good grasp of colors, sizes and some other style related HTML attributes.
i use this class TCPDF :
http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf
If you don't mind a bit of work then you can use Cairo to generate PDFs.
You can take a look at html2fpdf. It can accept very basic html and css.

Categories