Тёмный

How To Fill A Fillable PDF Form with PHP using PDFtk 

Mr Digital
Подписаться 30 тыс.
Просмотров 35 тыс.
50% 1

How to fill a PDF using PHP?
Have you ever wanted to know how to grab data from a form on a website and have it fill an already existing fillable PDF? Maybe you have a PDF with a form in it that you want to be filled in from a web form, so that it keeps the look and feel of your PDF with the data. Of course, you can fill in the PDF using Adobe Reader but what if your website form did it instead?
Well, PDFtk, along with PHP can help you achieve just that.
You can clone the project repository from here: github.com/mrdigitalau/PHP-PD...
This simple video will show you how to do it. I'll be creating a simple project showing you how to fill PDFs on your website.
I will not be doing form validation so that is something you will want to do if you plan on sending the project live. Don't
forget to do front end and back end validation.
PDFtk is a free tool for PDF Manipulation, and there is also a PDFTK Server, which we can use with PHP to manipulate PDFs.
Many other PDF libraries do not fill PDFs or make it very difficult to do so, PDFtk with php-pdftk is very simple to use.
PDFTk does not only fill PDFs, it can join PDFs together, it can remove files and add files. It can split files, add overlays and even
grab data from a PDF to use in PHP. This tutorial will simply show you how to fill PDFs, but the php-pdftk library can be used for more things.

Хобби

Опубликовано:

 

12 фев 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 133   
@mrdigitalau
@mrdigitalau 4 года назад
If you don't have adobe acrobat pro and want to find out the field names in a PDF - you can do it using pdftk [PDFNAME].pdf dump_data_fields - run this in terminal in the same folder the .pdf file is in, it will spit back all the fields and their names so you can map them with php pdftk.
@prane81
@prane81 4 года назад
Mr Digital thank you
@coraspa4091
@coraspa4091 2 года назад
Hello Mr Digital, If we have sample pdf but in current adobe we can't edit the form field name & also using pdftk can't fill form properly with fdf. So is it pdf issue ?
@lonnydavis5586
@lonnydavis5586 2 года назад
Great tutorial. Clear and concise and useful.
@saddamhossain-dr9fx
@saddamhossain-dr9fx 11 месяцев назад
Great explanation Mr Digital!. Thank you very much.
@DavidsonJasmin
@DavidsonJasmin 3 года назад
Thank you Mr. Digital.
@sanghisa
@sanghisa 2 года назад
Perfect explanation brother. Can we do the auto height based on the input text length?
@rachitshah6993
@rachitshah6993 Месяц назад
great tutorial thank you very much it saves lots of time.
@TheRamiroB
@TheRamiroB 3 года назад
great video!! One question I looking for any tool that can I embed inside my app, for generate pdf forms? do you know some app?
@SongvitItthiphisit
@SongvitItthiphisit 3 года назад
Can we fillable some field and then flatted it and other fields must be fill when open it with Reader or Acrobat?
@junkmatrix
@junkmatrix 4 года назад
I need the metadata from the original PDF also appear in the generated PDF. Will this code generate a brand new pdf file or make a copy of the existing PDF (i.e., test.pdf) and simply add form entries from PHP form page into it?
@cellocarlos
@cellocarlos Год назад
Is it possible add text like a header or a footer on a existing PDF and display it to the user (on the browser) using PDFtk?
@laurenmarie2035
@laurenmarie2035 3 года назад
BEFORE WATCHING THIS: Make sure you can install PDFtk on your server. This video is great and everything will work fine on your localhost. But you can't get it on many servers, especially if they are shared (unless someone out there has a workaround...???). Just a warning before you waste a bunch of time learning this.
@artkazun
@artkazun 2 года назад
so you can't just copy the existing project with the installed PDFtk from the localhost to your shared server?
@laurenmarie2035
@laurenmarie2035 2 года назад
@@artkazun Exactly. It won't work. The company you have your server with has to have PDFtk on their platform and you can't install it yourself. This is if you have a shared server.
@keremardicli4013
@keremardicli4013 2 года назад
@@laurenmarie2035 there are some pdftk composer packages out there based on pdftk. Would they work?
@jim9408
@jim9408 3 года назад
Hey Sean, Thank you. Your teaching style makes understanding the whole process easy to grasp. Have you used this same process (php-pdftk) for having someone electronically sign the PDF document?
@mrdigitalau
@mrdigitalau 3 года назад
Hello Jim, thank you very much. I don't use PDFTK for signatures because it is more used just to fill pdfs. If you want signatures it might be best to use DOMPDF or MPDF for that. You've given me a good idea for a tutorial, thanks mate!
@diangrove6931
@diangrove6931 2 года назад
@@mrdigitalau , I have the same question as Jim. Have you managed to make a tutorial on signing the PDF? Also which one DOMPDF or MPDF is best to use for this. Thanks mate.
@sthembisoncwane3412
@sthembisoncwane3412 4 месяца назад
@@diangrove6931 hey what i did is to use PDFtk for text and FPDi for signatures and it works great.
@sagaciousip
@sagaciousip 3 года назад
Hi, I have an add button on my PDF to generate dynamic fields. How I can generate and fill data dynamically using PHP?
@mdsafikulislam9113
@mdsafikulislam9113 4 года назад
Thank you so much Brother
@mrdigitalau
@mrdigitalau 4 года назад
You're welcome!
@happlyfly
@happlyfly 4 года назад
Safikul Bhai- could you run the project successfully and yield the expected PDF?
@chrisgabriel9086
@chrisgabriel9086 4 года назад
How can i input japanese character to the pdf form when generated?
@navnitjain
@navnitjain 4 года назад
it's working for unicode character?
@sakuragi9785
@sakuragi9785 2 года назад
to create the route of this is a post or a get route? (Route::get/Route::post)
@rosedematta4789
@rosedematta4789 4 года назад
I have a fillable PDF, after opening it in the browser, filling it with data, I want to save it as PDF. any help will be appreciated.
@agusnk6732
@agusnk6732 2 года назад
Thanks
@rohanshrestha8302
@rohanshrestha8302 2 года назад
Can we change the font of the pdf using pdftk?
@leopascal4812
@leopascal4812 3 года назад
Hello Mr. Digital, thanks for the great video, but I'm not getting any output PDF generated in the completed folder. any help would be apricated.
@dlk9572
@dlk9572 3 года назад
hello, did you find a solution?
@ferdinandiszlai8896
@ferdinandiszlai8896 3 года назад
I have the sam issue... it only generates the filename and prints it out to the screen.. it does not genereate the pdf. :(
@pietrolechthaler747
@pietrolechthaler747 4 года назад
Hi Mate, I want create an invoice file with my database's data. Do u think is a good way using this library?
@mrdigitalau
@mrdigitalau 4 года назад
Hi Pietro. If it were me, I would not use PDFTK for creating invoices. Unless the invoice is a fillable PDF. Otherwise you can use something like mPDF to create the PDF using HTML pulling data from the database.
@TIFO39
@TIFO39 5 месяцев назад
I have some issues hqving the new pdf in the completed folder. I'm using Hostinger by the way, so it's not local server So when I try to download the pdf from the link, I receive this error, "file wasn't available "
@albachirbenhammad1169
@albachirbenhammad1169 3 года назад
I got this error : Warning: copy(): The second argument to copy() function cannot be a directory in C:\xampp\htdocs\Project\vendor\mikehaertl\php-pdftk\src\Pdf.php on line 576 string(14) "pdf_255638.pdf" How Can I fix that!
@hakimfazal426
@hakimfazal426 3 года назад
how can we insert image.
@markusj3029
@markusj3029 9 месяцев назад
It looked very good at first sight. But if I got it right, it`s necessary to install pdftk-server. It might be easy on localhost, but how can I bring it to work on my productive site?!
@sthembisoncwane3412
@sthembisoncwane3412 4 месяца назад
Absolutely, @markusj3029, one effective approach to deploy the application form for your productive site is by hosting it on a virtual machine like AWS EC2. I've successfully hosted the application form on AWS EC2, which grants you complete control over the environment and facilitates the installation of necessary dependencies. Additionally, I've integrated additional libraries such as PHPMailer for seamless emailing of the application submissions and Fpdi for facilitating digital signatures. This setup ensures enhanced functionality and reliability for your application form. If you require further assistance or guidance on this setup, feel free to let me know!
@kyopan23
@kyopan23 Месяц назад
How would you include a checkbox?
@happlyfly
@happlyfly 4 года назад
Hi Mr. Digital- thanks for this great tutorial. Unfortunately, I am ending up with no saved file in the "completed" directory- cannot understand why. Any kind suggestion to resolve the problem will be very helpful. Thanks again!
@happlyfly
@happlyfly 4 года назад
Hi again Mr. Digital- any advise for me to resolve the "failed" outcome of the project? Thank you.
@vslslss4293
@vslslss4293 3 года назад
same problem here
@happlyfly
@happlyfly 3 года назад
@@vslslss4293 In the GeneratePDF file, please start with "namespace Classes;". This has to be the first line in the file for the whole thing to work
@cheikh_mutazila
@cheikh_mutazila 3 года назад
same problem
@ramg7808
@ramg7808 3 года назад
Hi. It doesnt work with open server, but it works with laragon. Maybe it because of Apache or Mysql
@pietrolechthaler747
@pietrolechthaler747 4 года назад
Mr Digital, Can I use this library without the composer? Can I download the library manually?
@mrdigitalau
@mrdigitalau 4 года назад
Hi Pietro. Yes you can, grab it off GitHub - github.com/mikehaertl/php-pdftk
@creativeartdesign4820
@creativeartdesign4820 2 года назад
Good work, i only have one question. Can i use it on my hosted webserver? what files do i need to upload to the hosting company ? Or did i understand it wrong, it is only need to be installed on the client? the plugin? PDFTK.
@masonholt651
@masonholt651 2 года назад
I have the same question. Did you ever find an answer?
@creativeartdesign4820
@creativeartdesign4820 2 года назад
@@masonholt651 No answer..yet.
@masonholt651
@masonholt651 2 года назад
@@creativeartdesign4820 I did a little more digging yesterday, and it seems like you need a dedicated server for this, and then this software has to be installed on it. Shared hosting just won't allow this software on it.
@osmaloureiro
@osmaloureiro Год назад
obrigado!
@mrdigitalau
@mrdigitalau Год назад
de nada!
@evelsimmon3938
@evelsimmon3938 3 года назад
Hi.Thanks for your video. I would like to get form fields names and values on my cpanel but I think we can 't use pdftk on cpanel. I made a mistake ? or is it possible to use on Cpanel too? As possible, please show me some example codes to help me. Thank you.
@afiqurrahman2884
@afiqurrahman2884 2 года назад
Hello sir, i have the problem...my problem is processed pdf not saved to completed directory...
@abdullaalrakib3652
@abdullaalrakib3652 2 года назад
after downloading it shows me Failed -No file ... how can I fix it i could not get any Solution till yet...please i need some help
@Richard-wb8vo
@Richard-wb8vo 3 года назад
Hi, I followed everything and this script does not end like yours do. I tried it in Mac OS with localhost, in Windows with WAMPP and onto my hosting server and every time I don't get anything, I tried also to download your code form GitHub and the only thing I got Is a file .pdf.html that has problems to open, I really don't know what to do, can you help me?
@dixon4946
@dixon4946 Год назад
Hi , did you find something for this
@wilsoncalaham5726
@wilsoncalaham5726 4 года назад
hi thanx for the great guid , i have a fatal error on the part you use "composer init" here the error i get ibb.co/yN5tzgb , would u please help me? im on centos 7 and using php7 , pdftk server is also installed successfully.
@mrdigitalau
@mrdigitalau 4 года назад
hi Wilson You need PHP to be installed on your machine. Are you using a web server on your local machine?
@scirpoliwebstudio5383
@scirpoliwebstudio5383 Год назад
congratulations for the tutorial. simple and direct language. i was able to follow it and get my application to work. however, it only works locally. why when I publish on my domain it doesn't generate the pdf file for me? thank you
@mrdigitalau
@mrdigitalau Год назад
Hi there, Thank you. You need to install PDFtk on your server. What server are you running?
@scirpoliwebstudio5383
@scirpoliwebstudio5383 Год назад
@@mrdigitalau Linux shl-buildd-bs03 4.19.0-22-amd64 #1 SMP Debian 4.19.260-1 (2022-09-29) x86_64 GNU/Linux
@mrdigitalau
@mrdigitalau Год назад
@@scirpoliwebstudio5383 Do you know how to SSH in and run commands by any chance? Using Putty or something similar? If you go here: snapcraft.io/install/pdftk/debian, run the commands on command line on your server, it should install it.
@scirpoliwebstudio5383
@scirpoliwebstudio5383 Год назад
@@mrdigitalau great. Thank you very much. I try, I hope to succeed and after the test I will let you know if I succeeded. Thanks for answering me :)
@mrdigitalau
@mrdigitalau Год назад
@@scirpoliwebstudio5383 You are welcome mate. Let me know either way. Hope you get it working. Cheers
@Joselson14
@Joselson14 4 года назад
Can I use Atom instead of Visual studio?
@mrdigitalau
@mrdigitalau 4 года назад
Of course mate. Any code editor your wish. As Vasu said, notepad even if you wanted. Would be a bit of a pain though :)
@usermiamiusa
@usermiamiusa Год назад
Hello, i excellent tutorial but i download your project but still getting error: Fatal error: Uncaught Error: Class 'Classes\GeneratePDF' not found in C:\xampp\htdocs\generate.php:23 Stack trace: #0 {main} thrown in C:\xampp\htdocs\generate.php on line 23
@0xjust1
@0xjust1 4 года назад
thanks a lot dude ! do you know how to import jpg to pdf with pdftk ?
@mrdigitalau
@mrdigitalau 4 года назад
Hey Justin, what do you want to do? Just add a pdf with an image into it as like a second pdf page? Or include an image onto the page?
@0xjust1
@0xjust1 4 года назад
@@mrdigitalau Thanks for your answer :) I just want to add an image in the pdf, like a field (jpeg_field) but apparently it's impossible to do that with pdftk.I'm looking for a way to include a jpg from the form, without results for the moment :(
@0xjust1
@0xjust1 4 года назад
@@mrdigitalau so, im trying to include an image onto the page ^^
@sthembisoncwane3412
@sthembisoncwane3412 4 месяца назад
​@@0xjust1 what helped me was to have a image upload tab then convert the image to base64 send it to PHP then use Fpdi to send the emage tio pdf
@devmev2665
@devmev2665 4 года назад
Just tested it on a Win 10 Machine with Version 1909, webserver is over XAMPP. Code seems to be working fine so far, the only thing is that the pdf is just not generated, so there is no file saved... Also can't see any errors with the getError() - method.. any help?
@devmev2665
@devmev2665 4 года назад
JUST FIXED IT! : It seems like this behaviour is known on windows systems, this lines (command and useExec) fixed it for me: $pdf = new Pdf('/path/my.pdf', [ 'command' => '/some/other/path/to/pdftk', // or on most Windows systems: // 'command' => 'C:\Program Files (x86)\PDFtk\bin\pdftk.exe', 'useExec' => true, // May help on Windows systems if execution fails ]); Also add this line after the save as: // Check for errors if (!$pdf->saveAs('my.pdf')) { $error = $pdf->getError(); } you have then the possibilty to log errors -> there i saw that i also have to use an absolut path for the "new PDF" -> 'C:\xampp\htdocs\test.pdf' Source: github.com/mikehaertl/php-pdftk#execution Edit: use the Full Windows Path also at the PDF File, thanks to the comments !
@happlyfly
@happlyfly 4 года назад
@@devmev2665 Very helpful. I am getting the same fruitless outcome - after seeing your comment, realized that its not just me. Unfortunately the above advice did not work for me...... still no pdf file is being generated or saved... Any kind suggestion will be very helpful.
@leopascal4812
@leopascal4812 3 года назад
@@devmev2665 Hello Jul Pod, I've tried this by implementing your msg also but still no success, any help would be apricated.
@Phop279
@Phop279 3 года назад
@@devmev2665 Needs to use the full windows path for pdf file too. Now It's work thanks
@ferdinandiszlai8896
@ferdinandiszlai8896 3 года назад
@@devmev2665 If i could hug you You would get a big fucking HUG!!
@MrJWVolleyball
@MrJWVolleyball Год назад
it appears at first glance that you did not create a fillable pdf, you created a form that created a flat pdf. I need a fillable pdf that has some parts filled in from a database source while the client gets to fill in the rest and send it back to me.
@dlk9572
@dlk9572 3 года назад
Hello, it's seem to work but the pdf file isn't generated can you help me please?
@Richard-wb8vo
@Richard-wb8vo 3 года назад
hi did you find a solution to this problem? I have the same and when I print the error in Mac OS it says command not found, thanks for help
@christopheransbaugh3946
@christopheransbaugh3946 3 года назад
Hey Sean, it looks like I have everything working, however, when I click download PDF it says, Failed - No file in the downloads. Any idea why?
@maxfxch
@maxfxch 3 года назад
Hi Christopher, got the same issue here, did you find a way to resolve this ?
@christopheransbaugh3946
@christopheransbaugh3946 3 года назад
@@maxfxch Yes, I did fix the issue. It was something super simple but I can't remember exactly what it was. I would recommend that you make sure whatever local server you're using has the most up -to-date PHP installed and also that you've installed Pdftk properly. You also should also ensure that all of your filepaths in the code are correct.
@maxfxch
@maxfxch 3 года назад
@@christopheransbaugh3946 Thanks for your concern. I updated everything I'm using PHP 8, using XAMPP for Php 8 still not working my short path are good too. I'll dig to find out a solution. Thanks !
@dlk9572
@dlk9572 3 года назад
@@maxfxch hello, did you find a solution?
@autoleader3441
@autoleader3441 2 года назад
Check bame of New pdf (‘(namefile.pdf)’) its same name of your file ?
@orlandol6260
@orlandol6260 4 года назад
what PC specs u have? seems fast
@mrdigitalau
@mrdigitalau 4 года назад
I've got an Intel i7-8700 3.20 GHz with 32 GB Ram :)
@prane81
@prane81 4 года назад
what if we donot have adobe pro?
@mrdigitalau
@mrdigitalau 4 года назад
HI Praneet, if you don't have adobe pro - use this in terminal. Run it in the same older the pdf is in. pdftk test.pdf dump_data_fields - it will give you a list of the field names
@santoshjayswal3905
@santoshjayswal3905 3 года назад
the video is great for local server but can you please give us any tip to use it on cpanel server. I find it very hard to install over there. any help would be appreciated
@aimanechouhaibi7397
@aimanechouhaibi7397 3 года назад
use ssh
@mohammadsbeaa737
@mohammadsbeaa737 2 года назад
@@aimanechouhaibi7397 what you mean by ssh?
@sippy28
@sippy28 4 года назад
But what about an image pdf form field?
@hakimfazal426
@hakimfazal426 3 года назад
did you found any solution?
@sthembisoncwane3412
@sthembisoncwane3412 4 месяца назад
what helped me was to have a image upload tab then convert the image to base64 send it to PHP then use Fpdi library to send the image to pdf
@harshgodhani1782
@harshgodhani1782 Год назад
I try to use this demo but it is not working. PDF is not generating. any suggestion?
@mrdigitalau
@mrdigitalau Год назад
You might not have PDFTK installed on your system, do you?
@prane81
@prane81 4 года назад
How to use this in live server?
@mrdigitalau
@mrdigitalau 4 года назад
Hi Praneet It really depends on what server you are using.. You will need to install PDFTK onto the server itself
@artkazun
@artkazun 2 года назад
@@mrdigitalau can I just copy the project folder with the installed PDFtk from the localhost to the server?
@RamzCompany
@RamzCompany 3 года назад
Undefined type 'mikehaertl\pdftk\Pdf'.intelephense(1009) any help all things install perfect
@dixon4946
@dixon4946 Год назад
Yo man, did you get anything that fixed this bug for you, cause I'm having the same problem as you were
@jovydelfin8933
@jovydelfin8933 3 года назад
Is it possible to insert an image?
@mrdigitalau
@mrdigitalau 3 года назад
As in, attaching an image to the fillable PDF?
@jovydelfin8933
@jovydelfin8933 3 года назад
@@mrdigitalau Yes. It's a signature that i want to put every time I generate the pdf. Basically the signature was already converted to image that I want to put in the pdf. You think it's possible?
@mrdigitalau
@mrdigitalau 3 года назад
@@jovydelfin8933 You should put the image into the PDF before it is filled by PHP . If you use adobe acrobat or some other PDF program you should be able to put an image in there.
@jovydelfin8933
@jovydelfin8933 3 года назад
@@mrdigitalau The signature is different for every record so that's not possible. What I want to achieve is to put signature dynamically same with the fillable fields.
@mrdigitalau
@mrdigitalau 3 года назад
@@jovydelfin8933 Then you probably can't use a fillable pdf. Try just creating the PDF from scratch with mPDF, then inserting the sig in there as an image. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-MnIps8Yc8CY.html
@ttaa6371
@ttaa6371 3 года назад
the problem of this PDFTK is that you cant use it online on a website. Unless someone knows how to. thanks
@mrdigitalau
@mrdigitalau 3 года назад
Yes you can. You need to install it onto your server. Do you have your own server?
@ttaa6371
@ttaa6371 3 года назад
@@mrdigitalau no it was on OVH or o2switch where i host my websites
@ttaa6371
@ttaa6371 3 года назад
i just make a program to add to a CRM i developped but if i cant put it online it was a waist of time !!! So i need help either to find a solution either to find another library doing the same thing
@TIFO39
@TIFO39 5 месяцев назад
I followed what you've mentioned but still it's not working. Im using VPS from hostinger, pdftk installed from centOS 64bit. Please any help would be very appreciated.
@krzyracergt
@krzyracergt 3 года назад
For anyone having issues with generating pdf, I got it to work by using an absolute path. $pdf = new Pdf('C:\xampp\htdocs\pdfgen\test.pdf', [ 'command' => 'C:\Program Files (x86)\PDFtk Server\bin\pdftk.exe', 'useExec' => true ]); $pdf->fillForm($data) ->flatten() ->saveAs('C:\xampp\htdocs\pdfgen\completed/' .$filename); return $filename;
@badchuckle
@badchuckle 3 года назад
this worked so well thank you
@sakuragi9785
@sakuragi9785 2 года назад
does anyone know the command for ubuntu?
@Src4mblerr
@Src4mblerr 2 года назад
Thank you so much! This worked!!!
@raoufdiak5453
@raoufdiak5453 2 года назад
Man you save my **s :D thanks
@niyazahamed8352
@niyazahamed8352 2 года назад
Thank You that worked , All we have to do is "GeneratePDF.php" and replace these (Check your personal file location) $pdf = new Pdf('C:\xampp\htdocs\pd\test.pdf', [ 'command' => 'C:\Program Files (x86)\PDFtk\bin\pdftk.exe', 'useExec' => true ]); $pdf->fillForm($data) ->flatten() ->saveAs('C:\xampp\htdocs\pd\completed/' .$filename); return $filename;
@LyninGaming
@LyninGaming Год назад
Stopped your video when you started OOP. I dont know it
@mrdigitalau
@mrdigitalau Год назад
Oh mate. You're missing out. What is it about OOP you don't get ? Happy to answer your queries
@TIFO39
@TIFO39 5 месяцев назад
Hey, I have pdftk installed via centOS on my own VPS (from Hostinger). The pdf is never saved in completed file? When I click on download file, open dialog opens but the file is changed to .htm instead of .pdf. After this: nothing is saved
Далее
Generate a PDF with PHP
19:17
Просмотров 59 тыс.
Create a PDF and Send by Email in PHP
20:57
Просмотров 66 тыс.
PORTAL SPAMMER🤬🤬🤬| Doge Gaming
00:19
Просмотров 1,9 млн
МЕСТЬ МАЛОГО
00:52
Просмотров 118 тыс.
How to Create Fillable PDF Form for FREE
19:30
Просмотров 859 тыс.
How I Coded An Entire Website Using ChatGPT
18:22
Просмотров 1,9 млн
Stop, Intel’s Already Dead!
13:47
Просмотров 150 тыс.
Top 10 CSS One Liners That Will Blow Your Mind
13:34
Просмотров 934 тыс.
How to put an HTML website online (on the Internet)
29:37
Always Check for the Hidden API when Web Scraping
11:50
How To Create a PDF using PHP - Simple Tutorial (2019)
18:40
😳РЫБАК УДИВИЛ ПРОХОЖИХ!
0:12
Просмотров 3,2 млн
А вы бы как с ним поступили?
0:22