Kernel::System::PDF - pdf lib
Functions for generating PDF files.
Don't use the constructor directly, use the ObjectManager instead:
my $PDFObject = $Kernel::OM->Get('Kernel::System::PDF');
Please note that currently you should only create one PDF object per instance of this class.
Create a new PDF Document
These font aliases are available in all methods: Proportional ProportionalBold ProportionalItalic ProportionalBoldItalic Monospaced MonospacedBold MonospacedItalic MonospacedBoldItalic
$True = $PDFObject->DocumentNew( Title => 'The Document Title', # Title of PDF Document Encode => 'utf-8', # Charset of Document Testfonts => 1, # (optional) default 0 );
Create a new, blank Page
$True = $PDFObject->PageBlankNew( Width => 200, # (optional) default 595 (Din A4) - _ both or nothing Height => 300, # (optional) default 842 (Din A4) - PageOrientation => 'landscape', # (optional) default normal (normal|landscape) MarginTop => 40, # (optional) default 0 - MarginRight => 40, # (optional) default 0 |_ all or nothing MarginBottom => 40, # (optional) default 0 | MarginLeft => 40, # (optional) default 0 - ShowPageNumber => 0, # (optional) default 1 );
Create a new Page
$PDFObject->PageNew( Width => 200, # (optional) default 595 (Din A4) Height => 300, # (optional) default 842 (Din A4) PageOrientation => 'landscape', # (optional) default normal (normal|landscape) MarginTop => 40, # (optional) default 0 MarginRight => 40, # (optional) default 0 MarginBottom => 40, # (optional) default 0 MarginLeft => 40, # (optional) default 0 ShowPageNumber => 0, # (optional) default 1 LogoFile => '/path/to/file.jpg', # (optional) you can use jpg, gif and png-Images HeaderRight => 'Header Right Text', # (optional) HeadlineLeft => 'Headline Text', # (optional) HeadlineRight => 'Headline Text', # (optional) FooterLeft => 'Footer Left Text', # (optional) FooterRight => 'Footer Right Text', # (optional) );
Return the PDF as string
$DocumentString = $PDFObject->DocumentOutput();
Add a table.
In case of missing or misused parameters, undef
is returned in scalar context and an empty list is returned in list context.
Return $Return{State} $Return{RequiredWidth} $Return{RequiredHeight} $Return{CellData} # (reference) complete calculated $Return{ColumnData} # (reference) complete calculated %Return = $PDFObject->Table( CellData => $CellData, # 2D arrayref (see example) ColumnData => $ColumnData, # arrayref (see example) RowData => $RowData, # arrayref (see example) Type => 'Cut', # (optional) default ReturnLeftOver (ReturnLeftOver|ReturnLeftOverHard|Cut) Width => 300, # (optional) default maximal width Height => 400, # (optional) default minimal height Font => 'Monospaced', # (optional) default Proportional (see DocumentNew()) FontSize => 9, # (optional) default 11 FontColor => 'red', # (optional) default black FontColorEven => 'blue', # (optional) cell font color for even rows FontColorOdd => 'green', # (optional) cell font color for odd rows Align => 'right', # (optional) default left (left|center|right) Lead => 3, # (optional) default 1 Padding => 18, # (optional) default 3 PaddingTop => 10, # (optional) top cell padding, overides Padding PaddingRight => 30, # (optional) right cell padding, overides Padding PaddingBottom => 30, # (optional) bottom cell padding, overides Padding PaddingLeft => 10, # (optional) left cell padding, overides Padding BackgroundColor => '#101010', # (optional) default white BackgroundColorEven => '#F0F0F0', # (optional) cell background color for even rows BackgroundColorOdd => '#A0A0A0', # (optional) cell background color for odd rows Border => 1, # (optional) default 1 (values between 0 and 20) BorderColor => '#FF0000', # (optional) default black ); $CellData = [ [ { Content => "Cell 1 (Row 1, Column 1)", # (optional) Font => 'Monospaced', # (optional) (see DocumentNew()) FontSize => 13, # (optional) FontColor => '#00FF00', # (optional) Align => 'center', # (optional) Lead => 7, # (optional) BackgroundColor => '#101010', # (optional) }, { Content => "Cell 2 (Row 1, Column 2)", }, ], [ { Content => "Cell 3 (Row 2, Column 1)", }, { Content => "Cell 4 (Row 2, Column 2)", }, ], ]; $ColumData = [ # this array was automaticly generated, if not given { Width => 11, # (optional) }, { Width => 44, }, ]; $RowData = [ # this array was automaticly generated, if not given { Height => 11, # (optional) }, { Height => 44, }, ];
Output a text line
Return $Return{State} $Return{RequiredWidth} $Return{RequiredHeight} $Return{LeftOver} %Return = $PDFObject->Text( Text => 'Text', # Text Width => 300, # (optional) available width of textblock Height => 200, # (optional) available height of textblock Type => 'Cut', # (optional) default ReturnLeftOver (ReturnLeftOver|ReturnLeftOverHard|Cut) Font => 'ProportionalBold', # (optional) default Proportional (see DocumentNew()) FontSize => 15, # (optional) default 10 Color => '#FF0000', # (optional) default #000000 Align => 'center', # (optional) default left (left|center|right) Lead => 20, # (optional) default 1 distance between lines );
Output a image
$True = $PDFObject->Image( File => '/path/image.gif', # (gif|jpg|png) Type => 'ReturnFalse' # (optional) default Reduce (ReturnFalse|Reduce) Width => 300, # width of image Height => 150, # height of image );
Output a horizontal line
$True = $PDFObject->HLine( Width => 300, # (optional) default 'end of printable dimension' Type => 'ReturnFalse' # (optional) default Cut (ReturnFalse|Cut) Color => '#101010', # (optional) default black LineWidth => 1, # (optional) default 1 );
Set new position on current page
$True = $PDFObject->PositionSet( Move => 'absolut', # (optional) default absolut (absolut|relativ) X => 10, # (optional) (<integer>|left|center|right) Y => 20, # (optional) (<integer>|top|middle|bottom) );
Get position on current page
Return $Position{X} $Position{Y} %Position = $PDFObject->PositionGet();
Set active dimension
$Dim = $PDFObject->DimSet( Dim => 'printable', # (optional) default content (content|printable) );
Get active dimension (printable or content)
$Dim = $PDFObject->DimGet();
This software is part of the OTRS project (https://otrs.org/).
This software comes with ABSOLUTELY NO WARRANTY. For details, see the enclosed file COPYING for license information (GPL). If you did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.