NAME
Document::Writer - Library agnostic document creation
SYNOPSIS
use Document::Writer;
use Graphics::Color::RGB;
# Use whatever you like
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);
...
$doc->add_component($textarea);
$self->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 pages to the document using either 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.
WARNING
This is an early release meant to shake support out of the underlying libraries. Further abstractions are forthcoming to make adding content to the pages easier than using Graphics::Primitive directly.
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.
- last_component
-
The last component in the list.
- 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.
SEE ALSO
Graphics::Primitive, Paper::Specs
AUTHOR
Cory Watson, <gphat@cpan.org>
Infinity Interactive, http://www.iinteractive.com
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
Copyright 2008 by Infinity Interactive, Inc.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.