Khonsu - PDF Generation!
Version 0.12
my @words = ('Aker', 'Anubis', 'Hapi', 'Khepri', 'Maahes', 'Thoth', 'Bastet', 'Hatmehit', 'Tefnut', 'Menhit', 'Imentet'); my $generate_text = sub { my $length = shift; return join " ", map { $words[int(rand(scalar @words))] } 1 .. $length; }; use Khonsu; Khonsu->load_plugin(qw/+Syntax/); my $padding = 20; my $page_padding = $padding * 2; my $khonsu = Khonsu->new( 'Ra', configure => { page_header => { padding => $padding, show_page_num => 'right', page_num_text => 'page {num}', h => $padding, cb => sub { my ($self, $file, %atts) = @_; $self->add( $file, text => 'Ra', align => 'center', %attrs, ); } }, page_footer => { padding => $padding, show_page_num => 'left', page_num_text => 'page {num}', h => $padding, cb => sub { my ($self, $file, %atts) = @_; $self->add( $file, text => 'Ra', align => 'center', %attrs, ); } }, toc => { title => 'Table of contents', title_font_args => { size => 50, }, title_padding => 10, font_args => { size => 20, }, padding => 5, }, h1 => { font => { colour => '#0EE' } } } ); $khonsu->add_image( image => 't/test.png', x => $padding, y => $padding, w => $khonsu->page->w - $page_padding, h => $khonsu->page->h - $page_padding, )->add_page; $khonsu->add_toc(); $khonsu->set_columns(2); for (0 .. 100) { $khonsu->add_h1( text => $generate_text->(3), toc => 1, )->add_text( text => $generate_text->(2000), indent => 4, font => { colour => '#fff' }, ); } $khonsu->set_columns(1); $khonsu->add_h1( text => 'A simple form', toc => 1 ); $khonsu->add_input( text => 'Name:' ); $khonsu->add_select( text => 'Colour:', options => [qw/red yellow green/] ); $khonsu->add_checkbox( text => 'Checkbox:' ); $khonsu->add_syntax( text => $perl_string ); $khonsu->save();
Get and set the PDF file name.
$khonsu->file_name(); $khonsu->file_name('PDFName');
Get and set the PDF::API2 object.
$khonsu->pdf(); $khonsu->pdf(PDF::API2->new( -file => sprintf("%s.pdf", $khonsu->file_name()) ));
Get and set the pdf pages Objects.
$khonsu->pages(); $khonsu->pages([Khonsu::Page->new( page_size =>'A4', num => 1, )->add($khonsu)];
Get and set the current page.
$khonsu->page(); $khonsu->page($khonsu->pages()->[0]);
Get and set the default page_args used when creating/adding a new page.
$khonsu->page_args(); $khonsu->page_args({ background => '#fff' });
Get and set the page_offset used while generating the table of contents.
$khonsu->page_offset(); $khonsu->page_offset(5);
Get and set onsave callbacks.
$khonsu->onsave_cbs(); $khonsu->onsave_cbs([ 'text', 'add', { text => 'On save callback', } ]);
Get and set the Khonsu::Shape::Line object.
$khonsu->line(); $khonsu->line(Khonsu::Shape::Line->new(%line));
Get and set the Khonsu::Shape::Box object.
$khonsu->box(); $khonsu->box(Khonsu::Shape::Box->new(%box));
Get and set the Khonsu::Shape::Circle object.
$khonsu->circle(); $khonsu->circle(Khonsu::Shape::Circle->new(%circle));
Get and set the Khonsu::Shape::Pie object.
$khonsu->pie(); $khonsu->pie(Khonsu::Shape::Pie->new(%pie));
Get and set the Khonsu::Shape::Ellipse object.
$khonsu->ellipse(); $khonsu->ellipse(Khonsu::Shape::Ellipse->new(%ellipse));
Get and set the Khonsu::Font object.
$khonsu->font(); $khonsu->font(Khonsu::Font->new(%font));
Get and set the Khonsu::Text object.
$khonsu->text(); $khonsu->text(Khonsu::Text->new(%text));
Get and set the Khonsu::Text::H1 object.
$khonsu->h1(); $khonsu->h1(Khonsu::Text::H1->new(%h1));
Get and set the Khonsu::Text::H2 object.
$khonsu->h2(); $khonsu->h2(Khonsu::Text::H2->new(%h2));
Get and set the Khonsu::Text::H3 object.
$khonsu->h3(); $khonsu->h3(Khonsu::Text::H3->new(%h3));
Get and set the Khonsu::Text::H4 object.
$khonsu->h4(); $khonsu->h4(Khonsu::Text::H4->new(%h4));
Get and set the Khonsu::Text::H5 object.
$khonsu->h5(); $khonsu->h5(Khonsu::Text::H5->new(%h5));
Get and set the Khonsu::Text::H6 object.
$khonsu->h6(); $khonsu->h6(Khonsu::Text::H6->new(%h6));
Get and set the Khonsu::Image object.
$khonsu->image(); $khonsu->image(Khonsu::Image->new(%image));
Get and set the Khonsu::TOC object.
$khonsu->toc(); $khonsu->toc(Khonsu::TOC->new(%toc));
Get and set the Khonsu::Form object.
$khonsu->form(); $khonsu->form(Khonsu::Form->new(%form));
Get and set the Khonsu::Form::Field::Input object.
$khonsu->input(); $khonsu->input(Khonsu::Form::Field::Input->new(%input));
Get and set the Khonsu::Form::Field::Select object.
$khonsu->select(); $khonsu->select(Khonsu::Form::Field::Select->new(%select));
Get and set the Khonsu::Form::Field::Checkbox object.
$khonsu->checkbox(); $khonsu->checkbox(Khonsu::Form::Field::Checkbox->new(%checkbox));
Load an external custom plugin.
package Khonsu::Test; use parent 'Khonsu::Text'; sub add { my ($self, $file, %attributes) = @_; return $self->SUPER::add($file, %attributes); } 1; ... Khonsu->load_plugin(qw/+Test/); my $khonsu = Khonsu->new( 'PDFName', configure => { test => { ... } } ); $khonsu->add_test(...);
Instantiate a new Khonsu Object and create an empty single page pdf.
my $khonsu = Khonsu->new( 'PDFName', %ATTRIBUTES, configure => { page_header => { padding => $padding, show_page_num => 'right', page_num_text => 'page {num}', h => $padding, cb => sub { my ($self, $file, %atts) = @_; $self->add( $file, text => 'Ra', align => 'center', %attrs, ); } }, page_footer => { padding => $padding, show_page_num => 'left', page_num_text => 'page {num}', h => $padding, cb => sub { my ($self, $file, %atts) = @_; $self->add( $file, text => 'Ra', align => 'center', %attrs, ); } }, toc => { title => 'Table of contents', title_font_args => { size => 50, }, title_padding => 10, font_args => { size => 20, }, padding => 5, }, } );
Add a new page to the pdf.
$khonsu->add_page( page_size => 'A4', background => '#fff', columns => 1, column => 1, column_y => 0, is_rotated => 0, header => Khonsu::Page::Header->new(%header), footer => Khonsu::Page::Footer->new(%footer), padding => 20, toc => 0, x => 0, y => 0, h => 842, w => 595, box => Khonsu::Shape::Box->new(%box) );
Set the number of page columns.
$khonsu->set_columns(2);
Open an existing page of the pdf.
$khonsu->open_page(1);
Add a custom header to the current page and all pages created/added after it.
$khonsu->add_page_header( padding => 20, show_page_num => 'right', page_num_text => 'page {num}', h => 20, cb => sub { my ($self, $file, %atts) = @_; $self->add( $file, text => 'Khonsu', align => 'center', %attrs, ); } );
Add a custom footer to the current page and all pages created/added after it.
$khonsu->add_page_footer( padding => 20, show_page_num => 'left', page_num_text => 'page {num}', h => 20, cb => sub { my ($self, $file, %atts) = @_; $self->add( $file, text => 'Khonsu', align => 'center', %attrs, ); } );
Remove the page header and footer for the current page.
$khonsu->remove_page_header_and_footer();
Remove the page header for the current page.
$khonsu->remove_page_header();
Remove the page footer for the current page.
$khonsu->remove_page_footer();
Add a table of contents to the document.
$khonsu->add_toc( title => 'Table of contents', title_font_args => { size => 50, }, title_padding => 10, font_args => { size => 20, }, padding => 5, x => 20, y => 20, w => $khonsu->page->w - 40, h => $khonsu->page->h - 40 );
Add text to the document.
$khonsu->add_text( text => 'This is a test ' x 24, x => 20, y => 120, w => 100, h => 120, );
Add a h1 to the document.
$khonsu->add_h1( text => 'This is a h1', );
Add a h2 to the document.
$khonsu->add_h2( text => 'This is a h2', );
Add a h3 to the document.
$khonsu->add_h3( text => 'This is a h3', );
Add a h4 to the document.
$khonsu->add_h4( text => 'This is a h4', );
Add a h5 to the document.
$khonsu->add_h5( text => 'This is a h5', );
Add a h6 to the document.
$khonsu->add_h6( text => 'This is a h6', );
Add a image to the document.
$khonsu->add_image( image => 't/test.png', align => 'center' );
Start a pdf form.
$khonsu->add_form();
Add a input to the document.
$khonsu->add_input( text => 'Input:', pad => '_' );
Add a select to the document.
$khonsu->add_input( text => 'Select:', options => [qw/one two three four/], pad => '_' );
Add a checkbox to the document.
$khonsu->add_checkbox( text => 'Checkbox:', );
Add a line to the document.
$khonsu->add_line( fill_colour => '#000', x => 140, y => 20, ex => 240, ey => 20 );
Add a box to the document.
$khonsu->add_box( fill_colour => '#000', x => 20, y => 20, w => 100, h => 100 );
Add a circle to the document.
$khonsu->add_circle( fill_colour => '#000', x => 260, y => 20, r => 50 );
Add a pie to the document.
$khonsu->add_pie( fill_colour => '#000', x => 380, y => 20, r => 50, rx => 360, ry => 40 ); $khonsu->add_pie( fill_colour => '#fff', x => 380, y => 20, r => 50, rx => 400, ry => 360 );
Add a ellipse to the document.
$khonsu->add_ellipse( fill_colour => '#000', x => 500, y => 20, w => 30, h => 50 );
Load a custom font.
$khonsu->load_font( colour => '#000', size => 20, family => 'Times', line_height => 25, );
LNATION, <email at lnation.org>
<email at lnation.org>
Please report any bugs or feature requests to bug-khonsu at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Khonsu. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-khonsu at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Khonsu
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
https://rt.cpan.org/NoAuth/Bugs.html?Dist=Khonsu
CPAN Ratings
https://cpanratings.perl.org/d/Khonsu
Search CPAN
https://metacpan.org/release/Khonsu
This software is Copyright (c) 2023 by LNATION.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Khonsu, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Khonsu
CPAN shell
perl -MCPAN -e shell install Khonsu
For more information on module installation, please visit the detailed CPAN module installation guide.