NAME
Document::Writer - Library agnostic document creation
SYNOPSIS
use Document::Writer;
use Graphics::Color::RGB;
# Use whatever you like, but this is best!
use Graphics::Primitive::Driver::CairoPango;
my $doc = Document::Writer->new;
my $driver = Graphics::Primitive::Driver::CairoPango->new(format => 'pdf');
# Create the first page
my @dim = Document::Writer->get_paper_dimensions('letter');
my $p = Document::Writer::Page->new(
color => Graphics::Color::RGB->new(red => 0, green => 0, blue => 0),
width => $dim[0], height => $dim[1]
);
$doc->add_page_break($driver, $page);
...
my $textarea = Document::Writer::TextArea->new(
text => 'Lorem ipsum...'
);
$textarea->font->size(13);
$textarea->padding(10);
$textarea->line_height(17);
$doc->add_component($textarea);
$doc->draw($driver);
$driver->write('/Users/gphat/foo.pdf');
DESCRIPTION
Document::Writer is a document creation library that is built on the Graphics::Primitive stack. It aims to provide convenient abstractions for creating documents and a library-agnostic base for the embedding of other components that use Graphics::Primitive.
When you create a new Document::Writer, it has no pages. You can add a page to the document using add_page_break($driver, [ $page ])
. The first time this is called, a page must be supplied. Subsequent calls will clone the last page that was passed in. If you add components to the document, then they will automatically be paginated at render time, if necessary. You only need to add the first page and any manual page breaks.
NOTICE
Document::Writer is a hobby project that I work on in my spare time. It's yet to be used for any real work and it's likely I've forgotten something important. Free free to contact me via IRC or email if you run into problems.
METHODS
add_component
Add a component to this document.
add_page_break ($driver, [ $page ])
Add a page break to the document. The first time this is called, a page must be supplied. Subsequent calls will clone the last page that was passed in.
clear_components
Remove all pages from this document.
draw ($driver)
Convenience method that hides all the Graphics::Primitive magic when you give it a driver. After this method completes the entire document will have been rendered into the driver. You can retrieve the output by using Driver's data or write methods. Returns the list of Page's as an arrayref.
find ($CODEREF)
Compatability and convenience method matching find
in Graphics::Primitive::Container.
Returns a new ComponentList containing only the components for which the supplied CODEREF returns true. The coderef is called for each component and is passed the component and it's constraints. Undefined components (the ones left around after a remove_component) are automatically skipped.
my $flist = $list->find(
sub{
my ($component, $constraint) = @_; return $comp->class eq 'foo'
}
);
If no matching components are found then a new list is returned so that simple calls liked $container->find(...)->each(...) don't explode.
get_paper_dimensions
Given a paper name, such as letter or a4, returns a height and width in points as an array. Uses Paper::Specs.
get_tree
Returns a Forest::Tree object with this document at it's root and each page (and it's children) as children. Provided for convenience.
last_component
The last component in the list.
SEE ALSO
Graphics::Primitive, Paper::Specs
AUTHOR
Cory Watson, <gphat@cpan.org>
BUGS
Please report any bugs or feature requests to bug-geometry-primitive at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Geometry-Primitive. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
COPYRIGHT & LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.