Good Morning All,

I have a question that I touched on a couple years ago, but then determined that I didn't need, so never followed up on it.

Now I need it... (of course)

I've searched on the subject of creating PDFs in PHP, but haven't been able to locate any specific answers to what I need to do, and wondered if someone could give me some feedback (positive preferably).

I have a retail site that the customer goes through a 4 step process to define the product they want to purchase along with any options to go with it.
In the 4th step, all the data is gathered and displayed in a table that represents the Purchase Order.

What I would like to do is to capture just that table (excluding the header and footer on the page), and create a PDF to attach to an email and send to the customer.

What was mentioned in the previous request 2 years ago was using html2pdf to generate the pdf, but it appears that it generates a pdf of the entire page as opposed to a portion of the page.

Does anyone have specific experience creating a pdf from a portion of a page and attaching it to an email as I've described?

Thanks in advance for your feedback.

Douglas

Thanks for the response Gideon 1, but I don't think that is exactly what I'm looking for.

I don't want the Customer to have to do anything special to receive the PDF, I just want to send it to them automatically when they go to make the payment.

Proposed your users click on a button to make a payment, you can add an event handler to that button such as onsubmit or onmousemove which will load the function without the users consent.

I used the 'fpdf Class' package (see www.fpdf.org) a couple of years ago to create PDF files. It wasn't terribly difficult to add it to PHP in my XAMPP installation on my computer, and it worked just fine. But my needs were very simple. The difficult part of your project is translating the HTML and CSS into the graphics primitives available in fpdf.

It's not terribly difficult to parse an HTML document and access the particular element(s) required for your PDF - especially if the documents are well-formed, valid HTML. And translating the limited number of HTML elements you're likely to encounter with your invoices would be tedious, but fairly simple as well. But if you have to parse the CSS rules to allow for maximum future flexibility, I'd be concerned. I'd be inclined to cheat and simply build in fixed rendering rules into my PHP script, rather than try to create the software required to really process the possible combinations of CSS rules.

And if all else fails, you can always just attach an HTML document rather than making yourself crazy trying to generate a perfect replica in PDF form. Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.