How can I generate a PDF dynamically?

Discussion in 'HTML & Website Design' started by MrLeN, Nov 5, 2013.

  1. #1
    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.
     
    MrLeN, Nov 5, 2013 IP
  2. TomHayes

    TomHayes Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #2
    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?
     
    TomHayes, Nov 5, 2013 IP
  3. MrLeN

    MrLeN Well-Known Member

    Messages:
    406
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    120
    #3
    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.
     
    MrLeN, Nov 5, 2013 IP
  4. ryan_uk

    ryan_uk Illustrious Member

    Messages:
    3,983
    Likes Received:
    1,022
    Best Answers:
    33
    Trophy Points:
    465
    #4
    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.
     
    ryan_uk, Nov 5, 2013 IP
  5. MrLeN

    MrLeN Well-Known Member

    Messages:
    406
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    120
    #5
    MrLeN, Nov 5, 2013 IP
  6. Pudge1

    Pudge1 Well-Known Member

    Messages:
    912
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    Digital Goods:
    1
    #6
    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
     
    Pudge1, Nov 8, 2013 IP
  7. rebertlee

    rebertlee Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #7
    You are absolutely right. I am totally agreed with you.

    Thanks
     
    rebertlee, Nov 9, 2013 IP
  8. subhadasdas

    subhadasdas Member

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #8
    <?php
    require('fpdf.php');
    
    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,'Hello World!');
    $pdf->Output();
    ?>
    Code (markup):
     
    subhadasdas, Nov 9, 2013 IP
  9. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #9
    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.
     
    kk5st, Nov 9, 2013 IP
  10. ryan_uk

    ryan_uk Illustrious Member

    Messages:
    3,983
    Likes Received:
    1,022
    Best Answers:
    33
    Trophy Points:
    465
    #10
    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.
     
    ryan_uk, Nov 9, 2013 IP