Download the PHP package kauffinger/php-pdftk-mcpdf without Composer
On this page you can find all versions of the php package kauffinger/php-pdftk-mcpdf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kauffinger/php-pdftk-mcpdf
More information about kauffinger/php-pdftk-mcpdf
Files in kauffinger/php-pdftk-mcpdf
Package php-pdftk-mcpdf
Short Description A PDF conversion and form utility based on mikehaertl/pdftk and vigicorp/php-mcpdf. Dynamically usable with mcpdf.
License MIT
Informations about the package php-pdftk-mcpdf
php-pdftk-mcpdf
A PDF conversion and form utility based on pdftk AND mcpdf.
This is a crude integration of mcpdf as an extra layer - use php-pdftk custom commands to use mcpdf. This is specifically meant to be used when filling forms with UTF-8 characters. NOTE: This implementation depends upon you having symlinked "mcpdf" to execute mcpdf.
Features
php-pdftk-mcpd brings the full power of pdftk
and mcpdf
to PHP - and more.
- Fill forms, either from a XFDF/FDF file or from a data array (UTF-8 safe for unflattened forms, requires pdftk 2.x !)
- Create XFDF or FDF files from PHP arrays (UTF-8 safe!)
- Create FDF files from filled PDF forms
- Combine pages from several PDF files into a new PDF file
- Split a PDF into one file per page
- Add background or overlay PDFs
- Read out meta data about PDF and form fields
- Set passwords and permissions
- Remove passwords
Requirements
- The
pdftk
command must be installed and working on your system - The
mcpdf
command must be installed and working on your system if you want to write UTF-8 chars - This library is written for pdftk 2.x versions. You should be able to use it with pdftk 1.x but not all methods will work there. For details consult the man page of pdftk on your system.
- There is a known issue
on Ubuntu if you installed the
pdftk
package from snap. This version has no permission to write to the/tmp
directory. You can either set another temporary directory as described below or use another package. For Ubuntu 18.10 there's also apdftk-java
package available via apt which should work fine. You can also install this package on Ubuntu 18.04 if you download it manually. Also check this answer on askubuntu.
Note: The pdftk version from the alternative PPA
ppa:malteworld/ppa
is no longer available. The author instead now points to his answer on askubuntu linked above.
Installation
This is meant as a drop-in replacement for your local php-pdftk
installation. There is no composer package yet.
Examples
Create instance for PDF files
There are several ways to tell the Pdf
instance which file(s) it should use.
Some files may also require a password or need an alias to be used as a handle
in some operations (e.g. cat or shuffle).
Note: In version 2.x of pdftk a handle can be one or more upper case letters.
Operations
Please consult the pdftk
man page for each operation to find out how each operation works
in detail and which options are available.
For all operations you can either save the PDF locally through saveAs($name)
or send it to the
browser with send()
. If you pass a filename to send($name)
the client browser will open a download
dialogue whereas without a filename it will usually display the PDF inline.
IMPORTANT: You can always only perform one of the following operations on a single PDF instance. Below you can find a workaround if you need multiple operations.
Fill Form
Fill a PDF form with data from a PHP array or an XFDF/FDF file. Note how the Pdf instance is created using the options array.
Note: When filling in UTF-8 data, you should always add the needAppearances()
option.
This will make sure, that the PDF reader takes care of using the right fonts for rendering,
something that pdftk can't do for you. Also note that flatten()
doesn't really work well
if you have special characters in your data.
Create a XFDF/FDF file from a PHP array
This is a bonus feature that is not available from pdftk
.
Cat
Assemble a PDF from pages from one or more PDF files.
Shuffle
Like cat()
but create "streams" and fill the new PDF with one page from each
stream at a time.
Burst
Split a PDF file into one file per page.
Add background PDF
Add another PDF file as background.
Add overlay PDF
Add another PDF file as overlay.
Attach Files
Add file attachments to the document or to a specific page.
Unpack Files
Copy file attachments from a PDF to the given directory.
Generate FDF
Create a FDF file from a given filled PDF form.
Get PDF data
Read out metadata or form field information from a PDF file.
How to perform more than one operation on a PDF
As stated above, you can only perform one of the preceeding operations on a single PDF instance.
If you need more than one operation you can feed one Pdf
instance into another:
Options
You can combine the above operations with one or more of the following options.
Shell Command
The class uses php-shellcommand to execute
pdftk
. You can pass $options
for its Command
class as second argument to the constructor:
Temporary File
Internally a temporary file is created via php-tmpfile. You can also access that file directly, e.g. if you neither want to send or save the file but only need the binary PDF content:
If you have permission issues you may have to set a directory where your
pdftk
command can write to:
API
Please consult the source files for a full documentation of each method.
All versions of php-pdftk-mcpdf with dependencies
mikehaertl/php-shellcommand Version ^1.6.3
mikehaertl/php-tmpfile Version ^1.1.0