1- # NAME
1+ # NAME
22
33CtrlO::PDF - high level PDF creator
44
@@ -8,11 +8,23 @@ CtrlO::PDF - high level PDF creator
88 use Text::Lorem;
99
1010 my $pdf = CtrlO::PDF->new(
11- logo => "sample/logo.png", # optional
12- orientation => "portrait", # Default
13- footer => "My PDF document footer",
14- PDFlib => "Builder", # Default
11+ logo => "sample/logo.png", # optional
12+ logo_scaling => 0.5, # Default
13+ width => 595, # Default (A4, portrait mode)
14+ height => 842, # Default (A4, portrait mode)
15+ orientation => "portrait", # Default
16+ margin => 40, # Default, all 4 sides
17+ top_padding => 0, # Default
18+ header => "My PDF document header", # optional
19+ footer => "My PDF document footer", # optional
1520 );
21+ # width, height page dimensions in points (default A4 paper)
22+ # orientation defaults to portrait (taller than wide)
23+ # margin in points on all four sides
24+ # top padding below header in points
25+ # header, footer text line to place at top or bottom
26+ # PDFlib actually checked only for '[aA]' or '[bB]', permitting a wide
27+ # range of formats to specify the PDF support library
1628
1729 # Add a page
1830 $pdf->add_page;
@@ -53,6 +65,16 @@ CtrlO::PDF - high level PDF creator
5365 print $pdf_out $file;
5466 close $pdf_out;
5567
68+ # From version 0.34 (and PDF::Builder 3.028) it is possible to produce
69+ # internal links in PDFs. For example:
70+ $pdf->text(<<'__MARKDOWN', format => 'md1');
71+ Go to an [internal link](link-elsewhere) somewhere else in this PDF.
72+
73+ ---
74+
75+ # System2 Configuration - Overview {#link-elsewhere}
76+ __MARKDOWN
77+
5678# DESCRIPTION
5779
5880This module tries to make it easy to create PDFs by providing a high level
@@ -62,15 +84,39 @@ pagination, headings, paragraph text, images and tables. Although there are a
6284number of other modules to create PDFs with a high-level interface, I found
6385that these each lack certain features (e.g. image insertion, paragraph text).
6486This module tries to include each of those features through another existing
65- module. Also, it is built on your choice of PDF::Builder or PDF::API2, and
66- provides access to that object, so content can also be added directly using
67- that, thereby providing any powerful features required.
87+ module. Also, as it is built on PDF::Builder, it provides access to that
88+ object, so content can also be added directly using that, thereby providing any
89+ powerful features required.
90+
91+ ** Updates in v0.20** Note that version 0.20 contains a number breaking changes
92+ to improve the default layout and spacing of a page. This better ensures that
93+ content added to a page "just works" in terms of its layout, without needing
94+ tweaks to its spacing. For example, headers have better spacing above and below
95+ by default. This means that PDFs produced with this version will be laid out
96+ differently to those produced with earlier versions. In the main, old code
97+ should be able to be updated by simply removing any manual spacing fudges (e.g.
98+ manual spacing for headers).
99+
100+ ** Updates in v0.30** Version 0.30 has some fairly major changes, dropping
101+ support of PDF::API2 and requiring use of PDF::Builder version 3.025. The
102+ latter contains many updates and powerful new features to create feature-rich
103+ PDF documents and means that PDF::TextBlock is no longer required for this
104+ module, which uses PDF::Builder's new column() method instead.
105+
106+ # CONSTRUCTOR
107+
108+ ## new
109+
110+ The constructor is called ` new ` , and accepts a optional hash of options.
111+ Valid options are mainly the same as all the methods described below, for those
112+ that get and set options. Some methods are read-only and must be set as options
113+ to the constructor, others can be set later.
68114
69115# METHODS
70116
71117## pdf
72118
73- Returns the ` PDF::Builder ` or ` PDF::API2 ` object used to create the PDF.
119+ Returns the ` PDF::Builder ` object used to create the PDF.
74120
75121## page
76122
@@ -97,7 +143,19 @@ Manually clears the is\_new\_page flag.
97143
98144## orientation
99145
100- Sets or returns the page orientation (portrait or landscape). Portrait is default.
146+ Sets or returns the page orientation (portrait or landscape). The default is
147+ Portrait (taller than wide).
148+
149+ ## PDFlib
150+
151+ Sets or returns the PDF-building library in use. The choices are "PDF::Builder"
152+ and "PDF::API2" (case-insensitive). "PDF::Builder" is the default, indicating
153+ that PDF::Builder will be used _ unless_ it is not found, in which case
154+ PDF::API2 will be used. If neither is found, CtrlO::PDF will fail.
155+
156+ ## font\_ size
157+
158+ Sets or returns the font size. Default is 10 (points).
101159
102160## width
103161
@@ -111,19 +169,33 @@ Sets or returns the height. Default is A4.
111169
112170Sets or returns the page margin. Default 40 pixels.
113171
172+ ## margin\_ top
173+
174+ Sets or returns the top margin. Defaults to the margin + top\_ padding +
175+ room for the header (if defined) + room for the logo (if defined).
176+
177+ ## margin\_ bottom
178+
179+ Sets or returns the bottom margin. Defaults to the margin + room for the
180+ footer.
181+
114182## top\_ padding
115183
116184Sets or returns the top padding (additional to the margin). Default 0.
117185
186+ ## header
187+
188+ Sets or returns the header text.
189+
118190## footer
119191
120192Sets or returns the footer text. Page numbers are added automatically.
121193
122194## font
123195
124- Sets or returns the font. This is based on ` PDF::Builder ` or ` PDF::API2 `
125- ttfont, which returns a TrueType or OpenType font object. By default, it
126- assumes the font is available in the exact path
196+ Sets or returns the font. This is based on PDF::Builder or PDF::API2 ttfont,
197+ which returns a TrueType or OpenType font object. By default it assumes the
198+ font is available in the exact path
127199` truetype/liberation/LiberationSans-Regular.ttf ` . A future
128200version may make this more flexible.
129201
@@ -152,53 +224,65 @@ write. Note that the value is measured from the bottom of the page.
152224
153225## set\_ y\_ position($pixels)
154226
155- Sets the current Y position. See _ y \_ position _ .
227+ Sets the current Y position. See [ "y \_ position" ] ( #y_position ) .
156228
157229## move\_ y\_ position($pixels)
158230
159231Moves the current Y position, relative to its current value. Positive values
160- will move the cursor up the page, negative values down. See _ y \_ position _ .
232+ will move the cursor up the page, negative values down. See [ "y \_ position" ] ( #y_position ) .
161233
162234## heading($text, %options)
163235
164236Add a heading. If called on a new page, will automatically move the cursor down
165237to account for the heading's height (based on the assumption that one pixel
166238equals one point). Options available are:
167239
168- size _n_
240+ - size _ n_
169241
170- `n` is the font size in points, **default 16**
242+ ` n ` is the font size in points, ** default 16**
171243
172- indent _n_
244+ - indent _ n_
173245
174- `n` is the amount (in points) to indent the text, **default 0**
246+ ` n ` is the amount (in points) to indent the text, ** default 0**
175247
176- topmargin _n_
248+ - topmargin _ n_
177249
178- `n` is the amount (in points) of vertical skip for the margin
179- _above_ the heading, **default 0**
250+ ` n ` is the amount (in points) of vertical skip for the margin _ above _ the
251+ heading, ** default: ** calculated automatically based on font size
180252
181- bottommargin _n_
253+ - bottommargin _ n_
182254
183- `n` is the amount (in points) of vertical skip for the margin
184- _below_ the heading, **default 10**
255+ ` n ` is the amount (in points) of vertical skip for the margin _ below _ the
256+ heading, ** default: ** calculated automatically based on the font size
185257
186258## text($text, %options)
187259
188- Add paragraph text. This will automatically paginate. Options available are:
260+ Add paragraph text. This will automatically paginate. Available options are
261+ shown below. Any unrecogised options will be passed to ` PDF::Builder ` 's Column
262+ method.
263+
264+ - format _ name_
265+
266+ ` name ` is the format of the text, in accordance with available formats in
267+ ` PDF::Builder ` . At the time of writing, supported options are ` none ` , ` pre ` ,
268+ ` md1 ` and ` html ` . If unspecified defaults to ` none ` .
189269
190- size _n_
270+ - size _ n_
191271
192- `n` is the font size in points, **default 10**
272+ ` n ` is the font size in points, ** default 10**
193273
194- indent _n_
274+ - indent _ n_
195275
196- `n` is the amount (in points) to indent the paragraph first line,
197- **default 0**
276+ ` n ` is the amount (in points) to indent the paragraph first line, ** default 0**
198277
199- color _name_
278+ - top \_ padding _ n _
200279
201- `name` is the string giving the text color, **default 'black'**
280+ ` n ` is the amount (in points) of padding above the paragraph, only applied if
281+ not at the top of a page. Defaults to half the line height.
282+
283+ - color _ name_
284+
285+ ` name ` is the string giving the text color, ** default 'black'**
202286
203287## table(%options)
204288
@@ -210,20 +294,37 @@ PDF::Table.
210294
211295Add an image. Options available are:
212296
213- scaling _n_
297+ - scaling _ n_
298+
299+ ` n ` is the scaling factor for the image, ** default 0.5** (50%)
300+
301+ - alignment _ name_
302+
303+ ` name ` is the horizontal alignment, ** default center**
304+
305+ ## has\_ state
306+
307+ A boolean dictating whether the version of PDF::Builder in use supports state
308+ functionality, to retain information across multiple pages.
309+
310+ ## state
214311
215- `n` is the scaling factor for the image, **default 0.5** (50%)
312+ A hashref to configure and store the PDF::Builder state information. By default
313+ this is built automatically using ` PDF::Builder->init_state() ` and includes
314+ configuration for the use of id parameters in header tags (enabling internal
315+ linking). See the [ PDF::Builder] ( https://metacpan.org/pod/PDF%3A%3ABuilder%3A%3AContent%3A%3AColumn_docs#init_state )
316+ documentation for more information.
216317
217318## content
218319
219320Return the PDF content.
220321
221322# LICENSE AND COPYRIGHT
222323
223- Copyright 2018-2020 Ctrl O Ltd
324+ Copyright 2018-2026 Ctrl O Ltd
224325
225326This program is free software; you can redistribute it and/or modify it under
226- the terms of either: the GNU General Public License (GPL) as published by the
327+ the terms of either: the GNU General Public License (GPL) as published by the
227328Free Software Foundation; or the Perl Artistic License (PAL).
228329
229330See http://dev.perl.org/licenses/ for more information.
0 commit comments