We help IT Professionals succeed at work.

PHP writing to a static pdf  file on web server

Atouray
Atouray asked
on
379 Views
Last Modified: 2013-12-12
I am developing a website that should have a downloadable PDF file on the server. On this file there should be a serial numbering that should change when ever the file is downloaded.

My approach to this is to create a table in the MySql DB with one field called serialNo the value of which increases by one each time you click on the download link. but the logic to write to the pdf is my problem.

Any help will be appreciated.
Comment
Watch Question

Commented:
You can use the fdf module which can run a script to fill form fields in the pdf.
Add a form field into the pdf where you'd like the serial number to appear.
In the code below, the 3rd line is where it says "serial" is where the name of the form field goes.
$value is the next serial number generated, that you want in the pdf file.
You'll need to enable the fdf module in php.ini and make sure you have fdf.dll available.
<?php
$fdf = fdf_create();
fdf_set_value($fdf, "serial", $value);
fdf_set_file($fdf, "file.pdf");
fdf_save($fdf, "input.fdf");
fdf_close($fdf);
Header("Content-type: application/vnd.fdf");
$fp = fopen("input.fdf", "r");
fpassthru($fp);
unlink("input.fdf");
?>

Open in new window

Author

Commented:
I did this just now but i am getting an error

Call to undefined function fdf_create()

I uncommented teh fdf module in php.ini file and the following dlls are

fdftk.dll
php_fdf.dll

Whats the problem

I restarted the server too.
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I have looked into FPDF but i cannot serialize the forms to be downloaded if this is possible then it might be an option that I can use.
is there any possibility for me to use this with databases.
Most Valuable Expert 2011
Author of the Year 2014

Commented:
FPDF is just a PHP class - of course you can use it with data bases.  It enables you to create valid PDF files from your own variable data, with very precise placement of text and images (like 1/100 inch).  I have used it to create even things as small as business cards that look great.  

What do you mean by "serialize the forms"?

Author

Commented:
I want each downloaded form to have a serial number i.e. a unique number so I can track the number of forms downloaded. From my own point of view I want to create one table in the database with one field maybe serialNo whose value is incremented when ever you download a form.

Can you hint me on how to use it with databases.
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Here is a really good book if you are beginning to learn PHP and data bases.
http://www.sitepoint.com/books/phpmysql4/

It will not make you a professional, but it will make things like this question into very easy answers.

Your design to have a table with one counting column (probably defined as INT NOT NULL AUTO_INCREMENT) is fine.  Whenever you get ready to create a PDF, you would insert a row into the table.  You might have more than one column in the table.  Maybe a DATETIME field and the user-id of whoever requested the PDF - things like that might be useful.  After your INSERT statement you would retrieve the last_insert_id() value and place that into the PDF.
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Thanks for the points - it's a great question! ~Ray

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.