Reputation: 2870
I am trying to make a function on a website whereby any article can be made into a PDF file for download and/or printing. I am using FPDF library but I'm struggling to understand the best way for my PDF page to receive the information.
What I am thinking so far is that I will make hidden form elements within the article page and then use them to send the information, take it and insert it into the PDF using $_POST. Something like:
<form action="pdf_printer.php" method="post">
<input type="hidden" name="title" value="<?php echo $title; ?>"/>
<input type="hidden" name="body_text" value="<?php echo $body_text; ?>"/>
<input type="submit" name="submit" value="Print">
</form>
And then the pdf_printer.php
would be something like:
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(60,10, $_POST['title'];,0,1,'C');
$pdf->Ln(20);
$pdf->Cell(60,10, $_POST['body_text'],0,1,'C');
$pdf->Output();
I'm sure this is a very inefficient way of doing this but as I'm relatively new to PHP I don't know how else it is done. Could someone please advise me?
Upvotes: 2
Views: 4152
Reputation: 6099
The best way to do this seems to make a PHP script generatepdf.php
in which you grab the article's text & title, and generate the pdf with FPDF. Then in article 12345 you can just add a link generatepdf.php?id=12345
and it will fetch the data from your database/files and generate the pdf for the user.
Upvotes: 1