I have a website which has an affiliate program, and each member has a different affiliate ID. I want to find a way to generate a custom PDF for each affiliate ID. ie: if someone clicks (from within the affiliate area) http://www.mysite.com/generate-flyer/?id=3 The PDF will load with information containing the ID number of 3. Then, the affiliate can print that out and distribute (and it will contain their own affiliate ID). Can anyone inform me of what I need in order to accomplish this? I know how to do it with a web page. Simply $_GET[''] the id number and echo it into the web page. But web pages aren't good for printing. That's what PDF's are for, Plus I've never created a PDF in my life, let alone a dynamically generated one.
I'm not sure how you could dynamically generate a PDF, but it may be easier and simpler to just use a print.css file... unless I'm missing something here?
I will explain another way. I want my affiliates to be able to download a flyer. However, I want that flyer to have their affiliate ID on it. It is all well and good to make a page look pretty for printing, but I can't make a web page fit an A4 piece of paper exactly. To ensure that I can use up all the space of an A4 piece for paper, I need to use a PDF (that's what they're for). But each affiliate needs a PDF that represents their own affiliate ID.
You will need to use an additional piece of software such as mPDF, TCPDF, dompdf, wkhtmltopdf or similar. As long as you can create the HTML page, then it will be straight forward to generate a PDF from it. You might need to experiment a bit until you find one that meets all your needs, perhaps start with mPDF first.
I have decided I will just use a HTML page. If I make sure that the "dimensions"of the page is "roughly" a4-ish.. it turns out alright-ish. Now I am having trouble getting the printer to print CSS background colors. Whole newproblem Case example 1: http://stackoverflow.com/questions/12730331/css-property-print-color-adjust-for-non-webkit-browsers I can't seem to win today.
You can install the PHP PDF library and then use the PDF functions to accomplish what you are trying to do if you know PHP. Otherwise I really don't think there is a way to generate a PDF "dynamically" Link: http://www.php.net/manual/en/book.pdf.php
<?php require('fpdf.php'); $pdf = new FPDF(); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello World!'); $pdf->Output(); ?> Code (markup):
The choice of printing (from html) or not printing background colors and images belongs entirely to the user. You can include backgrounds, but the user must explicitly set his print config to print them. The default is to not print backgrounds. Consider the consequence of this. If you set the text color to white, for example, expecting a dark background, you may end up with white on white.
Did you actually look at mPDF? Generate your HTML and then convert it using mPDF (or one of the other, similar alternatives). No, it's not native to PHP (you will need to include their library) but a simple way of generating a PDF on demand.