How to define printing options of a php generated pdf file? - php

I generate a PDF file from PHP with TCPDF classes. I would like to count the number of copies, because the original PDF file have to print once and the others have a header like second copy, third copy.
Is there any solution for this, or how can I check it after the user download the PDF?

You can't detect what the user is doing in the browser with PHP. You detect user interaction with the browser with JavaScript but I am fairly certain you cannot detect how many copies they are printing for security purposes.
Since the PDF is generated with PHP you can have a form saying how many copies they want and then generate one large PDF with all the copies and heading pages. They print this document once and get all the copies they need.

Related

How can I replace content in a PDF file using PHP?

I have one issue about PDF file.
I generate dynamic PDF template (Like Certificate). The file content some fields like Firstname, Lastname, Course type, etc.
I want to write dynamic content into PDF as firstname, lastname etc.
I have tried MPDF, FPDF etc tools, but they are not working. I also used PDF to HTML conversation but after converting HTML regenerates not possible from html into proper format.
Please let me know if anyone have other idea to direct replace content into Existing pdf using PHP.
I have sample pdf files.
I want to replace content into given attachment. This is a demo file I have many files with different templates.
Okay, get away from your thoughts one could easiely change anything in a pdf from PHP.
The one way to do such thing like generating a certificate for anyone is to generate a "blank" pdf and then put in the names with names with a php libarary (like Zend_Pdf or anything else).
To make it short: There is no (easy, free) way to manipulate data in a PDF.
To make it complicated: Yes, there is a way. One have to open the file, read it's content, understand where to search for the variables, manipulate the data and regenerate the pdf with a pdf generator. And yes, i know, it is very complicated, so stay at the short and easy way: Generate a blanko and put in the variables as needed ;)

Fill pdf form and insert image, without Pdftk

is there any possible way to not lose any content, when inserting an image into a filled pdf, i am using the fpdm.php script from here and works prettty good i might add. the pdfs i am using i pass them trough pdftk, as in pdftk.exe insert.pdf output output.pdf so they can be filled via php with out throwing errors
so my problem is this, i have a pdf template, which i use to fill it with an array passed from php, and output it to browser or server, and works ok, but when i try to insert an image into it, it inserts it, but loses all filled data, i need to retain that data. i cant use pdftk because im on a godaddy shared hosting plan, also setasign scripts works i know, but i am trying to find a way without buying anything yet.
i found this stamper which stamps ok but loses pdf data, all boxes get blanked, and also this one that places the image and loses all data too. setasign is doing some magic stuff right there
All mentioned scripts are using FPDI in the background which simply doesn't modifes the original document but will allow you to recreate a completely new PDF document by importing another one page by page into reuseable structures (XObjects). Because form fields or other dynamic content like links or any other annotation type are not part of a pages content stream they will get lost.
The mentioned "magic" of the SetaPDF products is, that they modify the original document. Because of this all content will retain.

Approach to generate generate pdf file from html page?

I studied wkhtmltopdf, tcpdf mechanism to generate pdf files. wkhtmltopdf where you directly pass a .html file and it gives you the pdf where in tcpdf you need to code entire pdf.
my case is I'm having a pdf form template Which I've converted into html so user can fill that form and after i fill that template with user entered values then I'll give an option to user to download the html (user filled) file as PDF document, so template will have user entered data next to that labels.
so first
PDF template >> convert to .HTML page >> process with php echoing >> convert it back with user input to a PDF file.
I'm confused here which approach I should use.
Install wkhtmltopdf on server and use it to pass .html page
problem: Everytime I need to save .html page on server and pass again it to wkhtmltopdf.
using TCPDF I need to write lots of code to create pdf exactly same as template PDF docs I'm having
and then using php echoing those user enterted values.
Which approach should i use If I'm expecting 1000+ users will be saving page as pdf at same time, approach which will be more easier and scalable in future.
First of all - I think you should go with the HTML form to PDF approach, so that's either wkhtmltopdf or a tool that already does this for you like PDFmyFORM.
In case you're expecting to go to 1000 saves concurrently then you definitely want to roll your own solution instead of going with an external service though.
There are patches in the wkhtmltopdf issue list that suggest caching (see this one) and you may also want to think about whether all these forms have to be generated as PDF again. You could use APC cache to somehow cache PDFs based on the same values being filled in. That could save you a bunch of time.
Other solutions you may want to look into are for example PhantomJS, which is a headless webkit browser too, but then based on JS - so that may reduce your server load alltogether...

Watermarking a PDF using PHP

I am using a PHP-based CMS for a private members site and need to implement a feature whereby whenever a user downloads a PDF, every page of the PDF gets watermarked clearly with something containing the username of the downloading user.
I previously used the Zend PHP library to add metadata in the Author field of the PDF containing the username, but the requirement has changed to show something visible to the user to act as a deterrant for sharing the document.
As far as I can tell, it's not possible (or at least simple) to do this using PHP. Is there an alternative to either do this using PHP or to serve the PDF downloads through another application that watermarks it on the fly?
One simple effective approach to this problem can be achieved with fpdf by rotating some watermark so that it's written across the page. Then You write on top of that. See http://www.fpdf.de/downloads/addons/9/

How can I make two different PDF files appear in the same iframe?

I used the FPDF class to create a multi-page PDF document and then I used an iframe to display the multi-page document.
Here is an example of the result:
I want to do the same thing on another page, except a bit different. Instead of displaying one multi-page PDF document, I would like to let the user upload two separate PDF's and then I display the two PDF's within the same iframe.
How can I make two different PDF files appear in the same iframe
The PDF plugin will take full control over the iframe, and can not deal with multiple files.
What you could do to work around it:
Two IFRAMEs
One easy solution that comes to mind is having a HTML page in the iframe, that in turn contains two iframes or even frames.
You'd have to find out whether this works for you - the devil will be in the detail here, for example, it will not be possible to synchronize the scroll positions or zoom levels, which is probably what you want.
Merge PDFs
The only real way to do this that I can think of is to generate a PDF that merges the two PDFs next to each other. This is not entirely trivial. Check out the following questions for example:
PHP - How to combine / merge multiple pdf’s
Need to merge multiple pdf’s into a single PDF with Table Of Contents sections
there are more on SO when searching for "PHP PDF merge".
I don't think you can, the users PDF reader may (if it's set to do so) display the PDF inline, therefore you can only have one per iframe...
But! What about having two iframes? This way You can display two PDFs easily.
I would go with the merge, as suggested by Pekka. The plugin rendering the PDF is afaik only capable of having one PDF.

Categories