PHP 클래스 mikehaertl\pdftk\Pdf

This class is a wrapper around pdftk. The class was developed for pdftk 2.x but should also work with older versions, but you may have to use slightly different page rotation options (e.g 'E' instead 'east').
저자: Michael Härtl ([email protected])
파일 보기 프로젝트 열기: mikehaertl/php-pdftk 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$ignoreWarnings whether to ignore any errors if some non-empty output file was still created. Default is false.

보호된 프로퍼티들

프로퍼티 타입 설명
$_command the command instance that executes pdftk
$_data the PDF data as returned from getData()
$_dataFields the PDF form field data as returned from getDataFields()
$_dataFields_utf8
$_data_utf8
$_error the error message
$_handle a counter for autogenerated handles
$_output the output filename. If null (default) a tmp file is used as output. If false, no output option is added at all.
$_pdf if the input was an instance, we keep a reference here, so that it won't get unlinked before this object gets destroyed
$_tmpFile the temporary output file
$_tmpOutputContentType the content type of the tmp output

공개 메소드들

메소드 설명
__construct ( string | Pdf | array $pdf = null, array $options = [] )
addFile ( string | Pdf $name, string | null $handle = null, string | null $password = null ) : Pdf
allow ( string | null $permissions = null ) : Pdf Set PDF permissions
background ( string $file ) : Pdf Apply a PDF as watermark to the background of a single PDF file.
burst ( string | null $filepattern = null ) : boolean Split the PDF document into pages
cat ( integer | string | array $start, integer | string | null $end = null, string | null $handle = null, string | null $qualifier = null, string $rotation = null ) : Pdf Assemble (catenate) pages from the input files.
compress ( boolean $compress = true ) : Pdf Restore/remove compression
dropXfa ( ) : Pdf Drop XFA data from forms created with newer Acrobat.
dropXmp ( ) : Pdf Drop XMP meta data
execute ( ) : boolean Execute the pdftk command and store the output file to a temporary location or $this->_output if set.
fillForm ( string | array $data, $encoding = 'UTF-8', $dropXfa = true, $format = 'xfdf' ) : Pdf Fill a PDF form
flatten ( ) : Pdf Flatten the PDF form fields values into a single PDF file.
generateFdfFile ( string $name ) : Pdf Generate the FDF file for a single PDF file.
getCommand ( ) : Command
getData ( boolean $utf8 = true ) : string | boolean
getDataFields ( boolean $utf8 = true ) : string | boolean
getError ( ) : string
getTmpFile ( ) : mikehaertl\tmp\File
keepId ( $id = 'first' ) : Pdf When combining multiple PDFs, use either the first or last ID in the output.
multiBackground ( string $file ) : Pdf Apply multiple PDF pages as watermark to the corresponding pages of a single PDF file.
multiStamp ( string $file ) : Pdf Add multiple pages from $file as overlay to the corresponding pages of a single PDF file.
needAppearances ( ) : Pdf Set need_appearances flag in PDF
passwordEncryption ( integer $strength = 128 ) : Pdf
saveAs ( string $name ) : boolean Execute the operation and save the output file
send ( string | null $filename = null, boolean $inline = false ) : boolean Send PDF to client, either inline or as download (triggers PDF creation)
setPassword ( string $password ) : Pdf
setUserPassword ( string $password ) : Pdf
shuffle ( integer | array $start, integer | null $end = null, string $handle = null, string | null $qualifier = null, string $rotation = null ) : Pdf Shuffle pages from the input files.
stamp ( string $file ) : Pdf Add $file as overlay to a single PDF file.

보호된 메소드들

메소드 설명
constrainSingleFile ( ) Make sure, that only one file is present
nextHandle ( ) : string

메소드 상세

__construct() 공개 메소드

public __construct ( string | Pdf | array $pdf = null, array $options = [] )
$pdf string | Pdf | array a pdf filename or Pdf instance or an array of filenames/instances indexed by a handle. The array values can also be arrays of the form array($filename, $password) if some files are password protected.
$options array Options to pass to set on the Command instance, e.g. the pdftk binary path

addFile() 공개 메소드

public addFile ( string | Pdf $name, string | null $handle = null, string | null $password = null ) : Pdf
$name string | Pdf the PDF filename or Pdf instance to add for processing
$handle string | null one or more uppercase letters A..Z to reference this file later. If no handle is provided, an internal handle is autocreated, consuming the range Z..A
$password string | null the owner (or user) password if any
리턴 Pdf the pdf instance for method chaining

allow() 공개 메소드

The available permissions are Printing, DegradedPrinting, ModifyContents, Assembly, CopyContents, ScreenReaders, ModifyAnnotations, FillIn, AllFeatures.
public allow ( string | null $permissions = null ) : Pdf
$permissions string | null list of space separated permissions or null for none.
리턴 Pdf the pdf instance for method chaining

background() 공개 메소드

The PDF file must have a transparent background for the watermark to be visible.
public background ( string $file ) : Pdf
$file string name of the background PDF file. Only the first page is used.
리턴 Pdf the pdf instance for method chaining

burst() 공개 메소드

Split the PDF document into pages
public burst ( string | null $filepattern = null ) : boolean
$filepattern string | null the output name in sprintf format or null for default 'pg_%04d.pdf'
리턴 boolean whether the burst command was successful

cat() 공개 메소드

Values for rotation are (in degrees): north: 0, east: 90, south: 180, west: 270, left: -90, right: +90, down: +180. left, right and down make relative adjustments to a page's rotation. Note: Older pdftk versions use N, E, S, W, L, R, and D instead. Example: $pdf = new Pdf; $pdf->addFile('file1.pdf', 'A') ->addFile('file2.pdf', 'B') ->cat(array(1,3),'B')) // pages 1 and 3 of file B ->cat(1, 5, 'A', 'odd') // pages 1, 3, 5 of file A ->cat('end', 5, 'B') // pages 5 to end of file B in reverse order ->cat(null, null, 'B', 'east') // All pages from file B rotated by 90 degree ->saveAs('out.pdf');
public cat ( integer | string | array $start, integer | string | null $end = null, string | null $handle = null, string | null $qualifier = null, string $rotation = null ) : Pdf
$start integer | string | array the start page number or an array of page numbers. If an array, the other arguments will be ignored. $start can also be bigger than $end for pages in reverse order.
$end integer | string | null the end page number or null for single page (or list if $start is an array)
$handle string | null the handle of the file to use. Can be null if only a single file was added.
$qualifier string | null the page number qualifier, either 'even' or 'odd' or null for none
$rotation string the rotation to apply to the pages.
리턴 Pdf the pdf instance for method chaining

compress() 공개 메소드

Restore/remove compression
public compress ( boolean $compress = true ) : Pdf
$compress boolean whether to restore (default) or remove the compression
리턴 Pdf the pdf instance for method chaining

constrainSingleFile() 보호된 메소드

Make sure, that only one file is present
protected constrainSingleFile ( )

dropXfa() 공개 메소드

Newer PDF forms contain both, the newer XFA and the older AcroForm form fields. PDF readers can use both, but will prefer XFA if present. Since pdftk can only fill in AcroForm data you should always add this option when filling in forms with pdftk.
public dropXfa ( ) : Pdf
리턴 Pdf the pdf instance for method chaining

dropXmp() 공개 메소드

Newer PDFs can contain both, new style XMP data and old style info directory. PDF readers can use both, but will prefer XMP if present. Since pdftk can only update the info directory you should always add this option when updating PDF info.
public dropXmp ( ) : Pdf
리턴 Pdf the pdf instance for method chaining

execute() 공개 메소드

You should probably never call this method unless you only need a temporary PDF file as result.
public execute ( ) : boolean
리턴 boolean whether the command was executed successfully

fillForm() 공개 메소드

Fill a PDF form
public fillForm ( string | array $data, $encoding = 'UTF-8', $dropXfa = true, $format = 'xfdf' ) : Pdf
$data string | array either a XFDF/FDF filename or an array with form field data (name => value)
리턴 Pdf the pdf instance for method chaining

flatten() 공개 메소드

Flatten the PDF form fields values into a single PDF file.
public flatten ( ) : Pdf
리턴 Pdf the pdf instance for method chaining

generateFdfFile() 공개 메소드

Generate the FDF file for a single PDF file.
public generateFdfFile ( string $name ) : Pdf
$name string name of the FDF file
리턴 Pdf the pdf instance for method chaining

getCommand() 공개 메소드

public getCommand ( ) : Command
리턴 Command the command instance that executes pdftk

getData() 공개 메소드

public getData ( boolean $utf8 = true ) : string | boolean
$utf8 boolean whether to dump the data UTF-8 encoded. Default is true.
리턴 string | boolean meta data about the PDF or false on failure

getDataFields() 공개 메소드

public getDataFields ( boolean $utf8 = true ) : string | boolean
$utf8 boolean whether to dump the data UTF-8 encoded. Default is true.
리턴 string | boolean data about the PDF form fields or false on failure

getError() 공개 메소드

public getError ( ) : string
리턴 string the error message or an empty string if none

getTmpFile() 공개 메소드

public getTmpFile ( ) : mikehaertl\tmp\File
리턴 mikehaertl\tmp\File the temporary output file instance

keepId() 공개 메소드

If not called, a new ID is created.
public keepId ( $id = 'first' ) : Pdf
리턴 Pdf the pdf instance for method chaining

multiBackground() 공개 메소드

If $file has fewer pages than the PDF file then the last page is repeated as background.
public multiBackground ( string $file ) : Pdf
$file string name of the background PDF file.
리턴 Pdf the pdf instance for method chaining

multiStamp() 공개 메소드

If $file has fewer pages than the PDF file then the last page is repeated as overlay.
public multiStamp ( string $file ) : Pdf
$file string name of the PDF file to add as overlay
리턴 Pdf the pdf instance for method chaining

needAppearances() 공개 메소드

This flag makes sure, that a PDF reader takes care of rendering form field content, even if it contains non ASCII characters. You should always use this option if you fill in forms e.g. with Unicode characters. You can't combine this option with flatten() though!
public needAppearances ( ) : Pdf
리턴 Pdf the pdf instance for method chaining

nextHandle() 보호된 메소드

protected nextHandle ( ) : string
리턴 string the next handle in the series A, B, C, ... Z, AA, AB...

passwordEncryption() 공개 메소드

public passwordEncryption ( integer $strength = 128 ) : Pdf
$strength integer the password encryption strength. Default is 128
리턴 Pdf the pdf instance for method chaining

saveAs() 공개 메소드

Execute the operation and save the output file
public saveAs ( string $name ) : boolean
$name string of output file
리턴 boolean whether the PDF could be processed and saved

send() 공개 메소드

Send PDF to client, either inline or as download (triggers PDF creation)
public send ( string | null $filename = null, boolean $inline = false ) : boolean
$filename string | null the filename to send. If empty, the PDF is streamed inline.
$inline boolean whether to force inline display of the PDF, even if filename is present.
리턴 boolean whether PDF was created successfully

setPassword() 공개 메소드

public setPassword ( string $password ) : Pdf
$password string the owner password to set on the output PDF
리턴 Pdf the pdf instance for method chaining

setUserPassword() 공개 메소드

public setUserPassword ( string $password ) : Pdf
$password string the user password to set on the output PDF
리턴 Pdf the pdf instance for method chaining

shuffle() 공개 메소드

This works the same as cat(), but each call to this method creates a "stream" of pages. The outfile will be assembled by adding one page from each stream at a time. Example: $pdf = new Pdf; $pdf1 = $pdf->addFile('file1.pdf'); $pdf->cat($pdf1, array(1,3,2)) ->cat($pdf1, array(4,5,9) ->saveAs('out.pdf'); This will give the page order 1, 4, 3, 5, 2, 9 in the out.pdf
public shuffle ( integer | array $start, integer | null $end = null, string $handle = null, string | null $qualifier = null, string $rotation = null ) : Pdf
$start integer | array the start page number or an array of page numbers.
$end integer | null the end page number or null for single page (or list if $start is an array)
$handle string the handle of the input file to use
$qualifier string | null the page number qualifier, either 'even' or 'odd' or null for none
$rotation string the rotation to apply to the pages. See cat() for more details.
리턴 Pdf the pdf instance for method chaining

stamp() 공개 메소드

The $file should have a transparent background.
public stamp ( string $file ) : Pdf
$file string name of the PDF file to add as overlay. Only the first page is used.
리턴 Pdf the pdf instance for method chaining

프로퍼티 상세

$_command 보호되어 있는 프로퍼티

the command instance that executes pdftk
protected $_command

$_data 보호되어 있는 프로퍼티

the PDF data as returned from getData()
protected $_data

$_dataFields 보호되어 있는 프로퍼티

the PDF form field data as returned from getDataFields()
protected $_dataFields

$_dataFields_utf8 보호되어 있는 프로퍼티

protected $_dataFields_utf8

$_data_utf8 보호되어 있는 프로퍼티

protected $_data_utf8

$_error 보호되어 있는 프로퍼티

the error message
protected $_error

$_handle 보호되어 있는 프로퍼티

a counter for autogenerated handles
protected $_handle

$_output 보호되어 있는 프로퍼티

the output filename. If null (default) a tmp file is used as output. If false, no output option is added at all.
protected $_output

$_pdf 보호되어 있는 프로퍼티

if the input was an instance, we keep a reference here, so that it won't get unlinked before this object gets destroyed
protected $_pdf

$_tmpFile 보호되어 있는 프로퍼티

the temporary output file
protected $_tmpFile

$_tmpOutputContentType 보호되어 있는 프로퍼티

the content type of the tmp output
protected $_tmpOutputContentType

$ignoreWarnings 공개적으로 프로퍼티

whether to ignore any errors if some non-empty output file was still created. Default is false.
public $ignoreWarnings