• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

How do I pass a php value to a pdf?

Hello,
I have a pdf (attached to this thread) with a form text field with the value "business".

I want to create a form on my website (php or html) where the user would enter in thier name of the business and click submit.

That would then create a new pdf (that the user could not edit) with thier business name filled in the business field (which is currently populated with the text "Enter Business Name") and it would save it on my web server and email me that value that was passed.

I have figured out how to create the pdf form and the email script.

But for the life of me I can't figure out how to pass the business value from the php form to the pdf.

Please help.

Thank you. BestOfSarasota.pdf BestOfSarasota.pdf
0
Razzmataz73
Asked:
Razzmataz73
  • 6
  • 3
1 Solution
 
Darude1234Commented:
It depends on how your PDF is created. You have to pass the values on your form to the PDF-creation function.
There are serveral available, for example:
http://ros.co.nz/pdf/
http://www.webdotdev.com/nvd/articles-reviews/php/php-extensions-pdflib-162-1.html
0
 
Ray PaseurCommented:
Learn about the excellent, free, open-source class FPDF.
http://fpdf.org/

I would not have the PDF be the thing that gets edited.  Instead I would create an HTML form and have the form submit the business name to a PHP script.  The PHP script can create the PDF file, store it on your server, and send you an email.
0
 
Ray PaseurCommented:
See http://www.laprbass.com/RAY_temp_razz.php
<?php // RAY_temp_razz.php
error_reporting(E_ALL);

// IF THE DATA WAS POSTED RUN THE ACTION SCRIPT
if (!empty($_POST["bizname"]))
{
    // SANITY CHECKS AS NEEDED GO HERE
    $bizname = preg_replace('/[^A-Z 0-9]/i', NULL, $_POST["bizname"]);
    $bizname = trim($bizname);
    $bizname = substr($bizname,0,16);
    if (!$bizname) die('SORRY - NOTHING USABLE IN BUSINESS NAME');


    // BRING IN THE PDF THING
    require_once('fpdf16/fpdf.php');

    // SYNTHESIZE THE PDF FILE INFORMATION
    $pdf_file_link = '/RAY_junk/' . 'temp_pdf_blue' . '.pdf';
    $pdf_file_name = getcwd()     . $pdf_file_link;

    // WRITE THE BUSINESS NAME IN WHITE ON A BLUE BACKGROUND
    $pdf=new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial', 'B', 16);
    $pdf->SetFillColor(  0,   0, 255);
    $pdf->SetTextColor(255, 255, 255);
    $pdf->Cell(40, 10, $bizname, 0, 2, 'L', TRUE);

    // WRITE THE PDF TO DISK
    $pdf->Output($pdf_file_name, 'F');

    // PRESENT A LINK
    echo '<a target="my_PDF" href="' . $pdf_file_link . '">' . $bizname . ' PDF</a>';
}

// THE FORM SCRIPT
$form = <<<FORM
<form method="post">
ENTER A BUSINESS NAME
<input name="bizname" />
<input type="submit" />
</form>
FORM;

echo $form;

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Razzmataz73Author Commented:
This is GREAT!  How do I get it to post the business name on my existing (BestOfSarasota.pdf) pdf and save it as a new one though?
0
 
Ray PaseurCommented:
I have no idea.  

Not saying that to be flip, just that I think you would need to create the BestOfSarasota.pdf using PHP and the FPDF class.  With some cut-and-paste in an image editor like Photoshop you can probably extract the main graphics from the BestOfSarasota.pdf and store them as PNG files in your file system.  Then you can use FPDF to retrieve and arrange the image(s) in the PDF.

IIRC, you can also use explicit positioning for both graphics and text.  So you could add the graphics to the PDF object first, then add the input from the form to write the business name.

FPDF gives you very fine granularity in positioning the parts of the PDF object.  I have even used it to create business cards!
0
 
Ray PaseurCommented:
OK, I tinkered around with this a little more.  Making some progress, tho not as much as I would like.  See:
http://www.laprbass.com/RAY_junk/temp_razz.pdf
http://www.laprbass.com/RAY_junk/razz.jpg
<?php // RAY_temp_razz.php
error_reporting(E_ALL);

// IF THE DATA WAS POSTED RUN THE ACTION SCRIPT
if (!empty($_POST["bizname"]))
{
    // SANITY CHECKS AS NEEDED GO HERE
    $bizname = preg_replace('/[^A-Z 0-9]/i', NULL, $_POST["bizname"]);
    $bizname = trim($bizname);
    $bizname = substr($bizname,0,16);
    if (!$bizname) die('SORRY - NOTHING USABLE IN BUSINESS NAME');


    // BRING IN THE PDF THING
    require_once('fpdf16/fpdf.php');

    // SYNTHESIZE THE PDF FILE INFORMATION
    $pdf_file_link = '/RAY_junk/' . 'temp_razz' . '.pdf';
    $pdf_file_name = getcwd()     . $pdf_file_link;

    // START THE PDF OBJECT
    $pdf = new FPDF('P','pt','Letter');
    $pdf->SetFont('Arial','B',32);
    $pdf->AddPage();
    $pdf->SetXY(1,1);

    // SET THE IMAGE
    $pdf->Image('RAY_junk/razz.jpg',1,1);
    $pdf->SetTextColor(50, 50, 0);
    $pdf->Text(188, 644, $bizname);

    // WRITE THE PDF TO DISK
    $pdf->Output($pdf_file_name, 'F');

    // PRESENT A LINK
    echo '<a target="my_PDF" href="' . $pdf_file_link . '">' . $bizname . ' PDF</a>';
}

// THE FORM SCRIPT
$form = <<<FORM
<form method="post">
ENTER YR BUSINESS NAME
<input name="bizname" />
<input type="submit" />
</form>
FORM;

echo $form;

Open in new window

0
 
Razzmataz73Author Commented:
Hi Ray,
This looks great and I am going to give it a shot first thing tomorrow.  I will let you know how it goes and reply back here.
0
 
Ray PaseurCommented:
Best of luck with it!
0
 
Razzmataz73Author Commented:
It is working!!!!  Thank you so much this was the missing piece I needed.
:)
0
 
Ray PaseurCommented:
Great!  Thanks for the points, ~Ray
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now