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.
Related
I am currently working on a web page that should do the following. As a little background, we are working on uploading a bunch of data that has a decent level of user-errors in the cell formatting to a database.
The data is stored in Excel spreadsheets. The spreadsheets are formatted in the same way, (99.9% of the time) but occasionally there are some wonky values within the cells themselves. Here is my goal: I would like the user to be able to
1) Provide the excel file to the page
2) Parse the file with PHP, then send the newly extracted data to a table on the page with editable cells
3) The user can see what came out of their file, then correct it for any slight errors before choosing to send the extracted data to the database.
I can do steps 2 and 3 using PHPExcel with a test file stored on the server, but I am having trouble getting from step 1 to step 2. My vision is to have the user specify the Excel spreadsheet and do the parsing without leaving the current page and losing the data in the fields. I would really like to keep the page from changing, as there are additional text fields on the page and I actually have to parse TWO spreadsheets before the data is taken from all of the fields and sent off to the database.
I guess I'm wondering if there's a way to use a client-provided file in PHP without doing a POST to upload. OR if there's a way to upload the file and have it parsed without leaving the page. I'm new to web development, so excuse me if those last few sentences made absolutely no sense.
Any thoughts?
PHP cannot do a single thing to the file until it is uploaded to the server. You could put a file upload form in an iframe and do some AJAX-y thing as described here.
As for handling PHP file uploads, the docs have a whole section.
I have a PHP script with HTML forms for user to pick several things, after that it communicates with database and prints out the result in the form of a table. Everything is formatted with CSS.
Now I would like to make those results also saved in an xls file, ideally using some sort of a "Save file" button appearing after the script finish its work. For that to work though I have to use PHPExcel write commands in several different parts of the script. But those parts are also responsible for the output on the website.
I have tried using PEAR and recently also PHPExcel and I think I can make it work with saving the file on the server, but I couldn't do it with sending to browser option (so popping up message with 'Save file as...'). When I try to do it that way, it prints out all kinds of gibberish signs on the website and doesn't pop up with save file option at all. I found out this is because I am printing and echoing all sort of things in between the PHPExcel write commands, but I am not sure how to do it differently.
So I guess my question is: Is it possible in PHPExcel or any other library to use its write commands all over the PHP script with all sort of echos and HTML code in between while using the send to browser option?
Thanks you in advance for answers and help.
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...
We have a high-resolution PDF (for printing) which has some form fields on it. We would like to have an HTML form which submits to the PDF, which is then placed into the respective fields.
I found a solution on google: http://koivi.com/fill-pdf-form-fields/
However, with that solution you only get an FDF file... And the demo does not work for me, opening the FDF file simply downloads another FDF file.
Since this PDF will be available to the public we would like to keep it as simple as possible. If we must open our original PDF and import this FDF file, we need a different solution (which I'm not sure is what the FDF file is for, since it didn't work).
A related post talking about .net framework had the same idea, but there were only paid commercial solutions: From HTML form to PDF
The PHP solutions I have found so far are for creating a new PDF, which is not what I need. Our PDF is created with Adobe Illustrator (or a similar adobe product) and is high-res with embedded fonts, svg and image content.
The form elements are in place, we just need to get the data to there.
Update April 11, 2013:
Since posting this question I have been utilizing FPDF on multiple projects where I needed to accomplish this goal. Although it cannot seem to "merge" template PDFs with the provided data, it can create the PDF from scratch.
One example I have used, I had a high resolution PNG for printing (similar to initial question) which we had to write the customer's name and today's date clearly in the center. I simply made the background of the PDF using FPDF->Image() and write the text afterwards using FPDF->Text().
It was very simple after all, you will need to look up the paper sizes to determine the X,Y,W,H of the image and then base your text fields relative to those numbers.
There was even a Form Filling extension, but I couldn't get it to work.
It seems as though I should answer my own question, although Visions answer may be better (seems to be deleted?). I used Vasiliy Faronov's link which was a comment to my main question: https://stackoverflow.com/a/1890835/200445
Here I found how to install pdftk and run a command to merge (flatten) my FDF and PDF files. I still used the "hacky" way to generate an FDF using Koivi's FDF Generator but it works for the most part.
One caveat is that some characters, like single and double quotes are not inserted correctly. It may be an issue of escaping the fields, but I could not find an answer.
Regardless, my PDF form generator is working, but anyone with a similar issue should look for a better solution.
There are number of tools which are not paid like itextsharp. try the following https://web.archive.org/web/20211020001747/https://www.4guysfromrolla.com/articles/030211-1.aspx Hope this code will help you. I have tried it its worked for me. If you can pay then there are number of paid tools which convert the HtML to PDF like ABCPDF etc.This example is in Asp.net and i am sure if you can convert it in PHP it will work for you too.
I have spent a lot of time trying to get dompdf (http://www.digitaljunkies.ca/dompdf/) to work but I keep running into problems. I am trying to generate a PDF from a PHP script which generates a fairly complex, filled out web form. The script accepts a $_GET parameter (record number) and fills out the form accordingly with data from the database. I have no problem getting this data into the script as a string or any type of value really. What I am wondering is what the best approach would be for converting this type of data to a PDF?
The flow is as follows: user completes form and is taken to confirmation page which I would like to add a "Save as PDF" button. At this point one of two things could happen, the page that is currently being displayed in the browser could be spun directly to a pdf or a call to itself (scriptname.php?id=xyz) could be made using something like PHP's http_get() function and store the HTML as a string. From there I am having issues with preparing an accurate representation as a PDF.
I have heard some talk about fpdf but their examples don't really lead me to believe you can use dynamic data as the source, but please correct me if I am wrong about this.
Any input would be appreciated.
-- Nicholas
Well, I didn't know dompdf. Strange that it uses either a commercial library (PDFlib) or an outdated (?) one (CPDF, not updated for 3 years). But well, as long as it works (concept is interesting).
I don't understand what you mean by "use dynamic data as the source" (or rather, I see not point in generating static PDF!), but FPDF is used to generate various dynamic documents, like invoices in e-commerce products. I saw people using forks (like TCPDF) to handle Unicode data, though.
You can't transform an HTML page to PDF with FPDF, but you have a quite precise control of layout, using concept of cells with data.
You can see such kind of code there: http://svn.prestashop.com/trunk/classes/PDF.php
In the past when faced with this issue, I have used FPDF for the placement of data on a PDF template. Then, by setting the appropriate HTTP header, force the browser to pop open the Download / Save As box for the user to save said PDF.
In a class that extends FPDF/FPDI appropriately, use something like the following to generate a PDF from a template PDF you've already created (http://www.setasign.de/products/pdf-php-solutions/fpdi/):
$this->setSourceFile('pdf_template.pdf');
$template_page = $this->importPage(1, '/MediaBox');
$this->useTemplate($template_page, 0, 0);
Then, have FPDF generate the PDF for output using:
$this->Output();
You can also extend FPDF to accept (limited) HTML for formatting using the script found here: http://www.fpdf.org/en/script/script41.php