1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
|
<html><head><title>PDF::Table</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >
</head>
<body class='pod'>
<!--
generated by Pod::Simple::HTML v3.45,
using Pod::Simple::PullParser v3.45,
under Perl v5.032001 at Wed Mar 20 00:52:35 2024 GMT.
If you want to change this HTML document, you probably shouldn't do that
by changing it directly. Instead, see about changing the calling options
to Pod::Simple::HTML, and/or subclassing Pod::Simple::HTML,
then reconverting this document from the Pod source.
When in doubt, email the author of Pod::Simple::HTML for advice.
See 'perldoc Pod::Simple::HTML' for more info.
-->
<!-- start doc -->
<a name='___top' class='dummyTopAnchor' ></a>
<div class='indexgroup'>
<ul class='indexList indexList1'>
<li class='indexItem indexItem1'><a href='#NAME'>NAME</a>
<li class='indexItem indexItem1'><a href='#SYNOPSIS'>SYNOPSIS</a>
<ul class='indexList indexList2'>
<li class='indexItem indexItem2'><a href='#EXAMPLE'>EXAMPLE</a>
</ul>
<li class='indexItem indexItem1'><a href='#DESCRIPTION'>DESCRIPTION</a>
<li class='indexItem indexItem1'><a href='#COMPATIBILITY'>COMPATIBILITY</a>
<ul class='indexList indexList2'>
<li class='indexItem indexItem2'><a href='#Maintaining_compatibility'>Maintaining compatibility</a>
<li class='indexItem indexItem2'><a href='#Run-time_changes'>Run-time changes</a>
</ul>
<li class='indexItem indexItem1'><a href='#METHODS'>METHODS</a>
<ul class='indexList indexList2'>
<li class='indexItem indexItem2'><a href='#new()'>new()</a>
<li class='indexItem indexItem2'><a href='#table()'>table()</a>
<ul class='indexList indexList3'>
<li class='indexItem indexItem3'><a href='#Table_settings'>Table settings</a>
<ul class='indexList indexList4'>
<li class='indexItem indexItem4'><a href='#Mandatory_global_settings'>Mandatory global settings</a>
<li class='indexItem indexItem4'><a href='#Optional_settings'>Optional settings</a>
<li class='indexItem indexItem4'><a href='#Optional_Global_Settings'>Optional Global Settings</a>
<li class='indexItem indexItem4'><a href='#Optional_Cell%2C_Column%2C_Row%2C_or_Global_Settings'>Optional Cell, Column, Row, or Global Settings</a>
<li class='indexItem indexItem4'><a href='#New_Page_Function_Hook'>New Page Function Hook</a>
<li class='indexItem indexItem4'><a href='#Cell_Render_Hook'>Cell Render Hook</a>
<li class='indexItem indexItem4'><a href='#Header_Row_Properties'>Header Row Properties</a>
<li class='indexItem indexItem4'><a href='#Row_Properties'>Row Properties</a>
<li class='indexItem indexItem4'><a href='#Column_Properties'>Column Properties</a>
<li class='indexItem indexItem4'><a href='#Cell_Properties'>Cell Properties</a>
</ul>
</ul>
<li class='indexItem indexItem2'><a href='#text_block()'>text_block()</a>
</ul>
<li class='indexItem indexItem1'><a href='#VERSION'>VERSION</a>
<li class='indexItem indexItem1'><a href='#AUTHOR'>AUTHOR</a>
<li class='indexItem indexItem1'><a href='#DEVELOPMENT'>DEVELOPMENT</a>
<li class='indexItem indexItem1'><a href='#COPYRIGHT_AND_LICENSE'>COPYRIGHT AND LICENSE</a>
<li class='indexItem indexItem1'><a href='#PLUGS'>PLUGS</a>
<li class='indexItem indexItem1'><a href='#CONTRIBUTION'>CONTRIBUTION</a>
<li class='indexItem indexItem1'><a href='#SEE_ALSO'>SEE ALSO</a>
</ul>
</div>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="NAME"
>NAME</a></h1>
<p>PDF::Table - A utility class for building table layouts in a PDF::Builder (or PDF::API2) object.</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="SYNOPSIS"
>SYNOPSIS</a></h1>
<p>Rather than cluttering up the following documentation with <b>(or PDF::API2)</b> additions,
wherever it refers to <code>PDF::Builder</code>,
understand that you can substitute <code>PDF::API2</code> to use that product instead <i>EXCEPT where noted</i>.</p>
<pre> use PDF::Builder;
use PDF::Table;
my $pdftable = new PDF::Table;
my $pdf = new PDF::Builder(-file => "table_of_lorem.pdf");
my $page = $pdf->page();
# some data to lay out
my $some_data =[
["1 Lorem ipsum dolor",
"Donec odio neque, faucibus vel",
"consequat quis, tincidunt vel, felis."],
["Nulla euismod sem eget neque.",
"Donec odio neque",
"Sed eu velit."],
# ... and so on
];
$left_edge_of_table = 50;
# build the table layout
# note: ignoring return values array
$pdftable->table(
# required parameters
$pdf,
$page,
$some_data,
'x' => $left_edge_of_table,
'w' => 495,
'y' => 500,
'h' => 300,
# some optional parameters
'next_y' => 750,
'next_h' => 500,
'padding' => 5,
'padding_right' => 10,
'bg_color_odd' => "gray",
'bg_color_even' => "lightblue", # cell bg color for even rows
'max_word_length' => 50, # 50 between forced splits
);
# do other stuff with $pdf
$pdf->save();
...</pre>
<h2><a class='u' href='#___top' title='click to go to top of document'
name="EXAMPLE"
>EXAMPLE</a></h2>
<p>For a complete working example or initial script look into distribution's 'examples' folder.</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="DESCRIPTION"
>DESCRIPTION</a></h1>
<p>This class is a utility for use with the PDF::Builder (or PDF::API2, see note above) module from CPAN. It can be used to display text data in a table layout within a PDF. The text data must be in a 2D array (such as returned by a DBI statement handle <code>fetchall_arrayref()</code> call). PDF::Table will automatically add as many new pages as necessary to display all of the data. Various layout properties, such as font, font size, cell padding, and background color can be specified for each column and/or for even/odd rows. Also a (non)repeated header row with different layout properties can be specified.</p>
<p>See the <a href="#METHODS" class="podlinkpod"
>"METHODS"</a> section for complete documentation of every parameter.</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="COMPATIBILITY"
>COMPATIBILITY</a></h1>
<p>Starting with version 1.000, several behaviors have changed (for the better, I believe). Nevertheless, there may be some users who prefer the old behaviors. To keep everybody happy, it is possible to easily revert to the old behaviors. Near the top of Table.pm, look for a section labeled <code>COMPATIBILITY WITH OLDER VERSIONS</code>. You can change settings here to match old behaviors:</p>
<dl>
<dt><a name="repeating_headers"
>repeating headers</a></dt>
<dd>
<p>The old default for the <code>repeat</code> setting for a header was '0' (do not repeat after a table has been split across a page). I believe that most users will want to automatically repeat a header row at the start of each table fragment, but you can change this behavior if you wish. Change <code>$repeat_default</code> from 1 to 0 to get the old behavior (or, explicitly give <code>repeat => 0</code> in the header properties settings).</p>
<dt><a name="which_rows_are_'odd'_(and_which_are_'even')"
>which rows are 'odd' (and which are 'even')</a></dt>
<dd>
<p>PDF::Table decided which rows were odd/even (background and foreground colors, etc) in an inconsistent manner, especially if a header was used (whether repeated or not). Now, the first data row (excluding headers) is "odd", and all rows after that alternate "even", "odd", etc., even across page breaks. If you want the old behavior, it can be requested. Change <code>$oddeven_default</code> from 1 to 0 to get the old behavior.</p>
<dt><a name="default_cell_padding"
>default cell padding</a></dt>
<dd>
<p>The old default for padding around the contents of a cell was 0. It is now 2pt. Change <code>$padding_default</code> from 2 to 0 to get the old behavior.</p>
<dt><a name="behavior_of_borders"
>behavior of borders</a></dt>
<dd>
<p>The old behavior was calling both the frame around the table <i>and</i> the cell-divider rules as "border", and using the same settings for both. This has been changed to separate the two classes, with "border" referring to the outside framework, and "rules" referring to the dividers. Note that "rules" still inherit from "border", so an explicit definition of <code>rules => 0</code> (to hide interior rules) or another width (line weight) may still be needed to override the "border" setting for interior dividers.</p>
</dd>
</dl>
<h2><a class='u' href='#___top' title='click to go to top of document'
name="Maintaining_compatibility"
>Maintaining compatibility</a></h2>
<p>Near the top of file Table.pm, look for <code>my $compat_mode = 0;</code>. PDF::Table is shipped with a flag of <code>0</code> to use the new features of the library. If you have a pressing need to maintain compatibility with older versions of the library, you may change the value to <code>1</code>. Note that a flag of <code>1</code> will break some of the t-tests, because of different padding defaults resulting in different text locations on the page.</p>
<h2><a class='u' href='#___top' title='click to go to top of document'
name="Run-time_changes"
>Run-time changes</a></h2>
<p>If you do not wish to change the PDF::Table code section to permanently change old-versus-new behavior, you can use the <i>compatibility</i> flag in the settings to temporarily change the variables listed above.</p>
<pre> compatibility => [ 0, 0, 0 ]</pre>
<p>will restore all behaviors to the old style, while</p>
<pre> compatibility => [ 1, 0, 2 ]</pre>
<p>will change only the designation of "odd/even" rows (element 1) to the old behavior, while leaving header repeat (element 0) and default padding (element 2) in the new behavior.</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="METHODS"
>METHODS</a></h1>
<h2><a class='u' href='#___top' title='click to go to top of document'
name="new()"
>new()</a></h2>
<pre> my $pdf_table = new PDF::Table;
or
my $pdf_table = PDF::Table->new();</pre>
<dl>
<dt><a name="Description"
>Description</a></dt>
<dd>
<p>Creates a new instance of the class.</p>
<dt><a name="Parameters"
>Parameters</a></dt>
<dd>
<p>There are no required parameters. You may pass $pdf, $page, $data, and %options; or can defer this until the table() method invocation (the usual technique).</p>
<dt><a name="Returns"
>Returns</a></dt>
<dd>
<p>Reference to the new instance</p>
</dd>
</dl>
<h2><a class='u' href='#___top' title='click to go to top of document'
name="table()"
>table()</a></h2>
<p>Generate output:</p>
<pre> my ($final_page, $number_of_pages, $final_y) = table($pdf, $page, $data, %settings)</pre>
<p>or, just report row sizes:</p>
<pre> my @v_sizes = table($pdf, $page, $data, %settings, 'ink' => 0)</pre>
<dl>
<dt><a name="Description"
>Description</a></dt>
<dd>
<p>Generates a multi-row, multi-column table into an existing PDF document, based on provided data set and settings.</p>
<dt><a name="Parameters"
>Parameters</a></dt>
<dd>
<pre> $pdf - a PDF::Builder instance representing the document being created
$page - a PDF::Builder::Page instance representing the current page of
the document
$data - an ARRAY reference to a 2D data structure that will be used
to build the table
%settings - HASH with geometry and formatting parameters</pre>
<p><b>$data</b> is normally an m x n matrix of strings, each string containing the content text of that cell, and arranged with each row being an anonymous array of strings. For example, a table of 3 rows of 4 columns would be</p>
<pre> $data = [
[ 'c1', 'c2', 'c3', 'c4' ], # row 1
[ 'c1', 'c2', 'c3', 'c4' ], # row 2
[ 'c1', 'c2', 'c3', 'c4' ], # row 3
];</pre>
<p><b>For PDF::Builder ONLY:</b></p>
<p>If you wish to enable <i>markup</i> (Markdown or HTML) for a cell, <code>$data</code> has the same structure, except that a cell with markup is itself an anonymous array of three items: a string describing the markup ('none', 'md1', 'html', or 'pre'), a string or anonymous array of strings representing the text and markup for the cell, and an anonymous hash of settings pertaining to the <code>column()</code> call. See PDF::Builder's POD for Content::Text for details.</p>
<p>Instead of plain text cell 'This is plain text', you can do something like:</p>
<pre> [ 'html',
'<p><font color="green">This is green text.</font></p>',
{ 'font-family'=>'Serif', 'font-size'=>15, 'para'=>[0,0] } ]</pre>
<p>Remember, this works only with PDF::Builder, and <i>not</i> with PDF::API2. See the "Column.pl" example on PDF::Builder for some examples. Automatic cell sizing will not work with this, so you need to use the <code>size</code> table parameter to specify relative cell widths.</p>
<p><b>End of PDF::Builder ONLY:</b></p>
<p>For full <code>%settings</code> description see section <a href="#Table_settings" class="podlinkpod"
>"Table settings"</a> below.</p>
<p>This method will add more pages to the PDF instance as required, based on the formatting options and the amount of data.</p>
<dt><a name="Returns"
>Returns</a></dt>
<dd>
<p>If actually creating PDF output, the return value is a 3 item list where</p>
<pre> $final_page - A PDF::Builder::Page instance that the table ends on
$number_of_pages - The count of pages that the table spans
$final_y - The Y coordinate of the table bottom, so that additional
content can be added on the same page ($final_page)</pre>
<p>If just requesting the table size (<code>'ink' => 0</code>), the return value is an <code>N+3</code> item list where</p>
<pre> item [0] is the overall table length (height) in points
item [1] is the header height in points (0 if no header used)
item [2] is the footer height in points (currently 0)
item [3] is the height of data row 1
item [4] is the height of data row 2
...
item [N+3] is the height of data row N</pre>
<p>See <code>examples/vsizes.pl</code> for some examples of determining sizes of a table and its rows. This may be useful information for you in deciding whether there is space on <i>this</i> page to fit the complete table, or if you should go to the top of the next page. It could be used to figure how to set <i>h</i> to fit complete rows on a page (not splitting rows), or even how to re-order the rows to most efficiently display them (on the fewest number of pages) without splitting any row.</p>
<p>Two things to note:</p>
<p>1. The table data must be refreshed before calling the table method a second time (to actually output PDF, with ink = 1).</p>
<p>2. If the table spills over onto a new page when outputting the PDF (ink = 1), you will need to retrieve the new <code>$page</code> hash via the return code. Actually, you would need to do this even if you are not querying table sizes!</p>
<dt><a name="Example"
>Example</a></dt>
<dd>
<pre> my $pdf = new PDF::Builder;
my $page = $pdf->page();
my $data = [
['foo1','bar1','baz1'],
['foo2','bar2','baz2']
];
my %settings = (
'x' => 10,
'w' => 570,
'y' => 220,
'h' => 180,
);
my ($final_page, $number_of_pages, $final_y) =
$pdftable->table( $pdf, $page, $data, %options );</pre>
</dd>
</dl>
<h3><a class='u' href='#___top' title='click to go to top of document'
name="Table_settings"
>Table settings</a></h3>
<p>Unless otherwise specified, all dimensional and geometry units used are measured in <i>points</i>. Line counts are not used anywhere.</p>
<p>"Even" rows start with the first data (non-header) row. Think of this first row as number zero (an <i>even</i> number). Even rows alternate with odd rows. The odd/even flag is <b>not</b> reset when a table is split across pages. If a table fragment ends on an odd row, the next fragment (on the next page), starting the next row, will start with an even row. If a <i>row</i> is split across pages, it will resume with the same odd/even setting as on the previous page. If you desire to have the old (previous) odd/even behavior, see <a href="#COMPATIBILITY" class="podlinkpod"
>"COMPATIBILITY"</a>.</p>
<p>The name (key) of any table setting hash element may be given with or without a leading dash (hyphen). A leading dash is allowed for compatibility with older versions of PDF::Table, but is <b>DEPRECATED!</b> It is recommended that the dash be omitted in new code, and removed from old code before November 2022.</p>
<p><b>Note:</b> if you use a deprecated setting name, or a setting beginning with a hyphen '-', PDF::Table will update the settings list with the preferred name. It does this by inserting the item using the preferred, non-hyphen name, and then deletes the deprecated one. Due to peculiarities in the way Perl copies arrays, hashes, and references; it is possible that your input settings hash may end up being modified! This normally will not be a cause for concern, but you should be aware of this behavior in case you wish to reuse all or part of a PDF::Table settings list (hash) for other purposes (or another table) -- it may have been slightly modified.</p>
<p>Note that any "Color specifier" is not limited to a name (e.g., 'black') or a 6-digit hex specification (e.g., '#3366CC'). See the PDF::Builder writeup on specifying colors for CMYK, L*a*b, HSV, and other methods.</p>
<h4><a class='u' href='#___top' title='click to go to top of document'
name="Mandatory_global_settings"
>Mandatory global settings</a></h4>
<p>There are some mandatory parameters for setting table geometry and position on the first (initial) or only page of the table. It is up to you to tell PDF::Table where to start (upper left corner) the table, and its width and maximum height on this page.</p>
<dl>
<dt><a name="x_-_X_coordinate_of_upper_left_corner_of_the_table."
><b>x</b> - X coordinate of upper left corner of the table.</a></dt>
<dd>
<p>The left edge of the sheet (media) is 0. <b>Note</b> that this <code>X</code> will be used for any spillover of the table to additional page(s), so you cannot have spillover (continuation) rows starting at a different <code>X</code>.</p>
<p><b>Value:</b> can be any number satisfying <code>0 ≤ X < PageWidth</code></p>
<p><b>Default:</b> No default value</p>
<pre> 'x' => 10,</pre>
<dt><a name="y_-_Y_coordinate_of_upper_left_corner_of_the_table_on_the_initial_page."
><b>y</b> - Y coordinate of upper left corner of the table on the initial page.</a></dt>
<dd>
<p><b>Value:</b> can be any number satisfying <code>0 < y < PageHeight</code> (depending on space availability when embedding a table)</p>
<p><b>Default:</b> No default value</p>
<pre> 'y' => 327,</pre>
<p><b>Deprecated name:</b> <i>start_y</i> (will go away in the future!)</p>
<dt><a name="w_-_width_of_the_table_starting_from_x."
><b>w</b> - width of the table starting from <code>x</code>.</a></dt>
<dd>
<p><b>Note</b> that this <code>width</code> will be used for any spillover of the table to additional page(s), so you cannot have spillover (continuation) rows with a different <code>width</code>.</p>
<p><b>Value:</b> can be any number satisfying <code>0 < w < PageWidth - x</code></p>
<p><b>Default:</b> No default value</p>
<pre> 'w' => 570,</pre>
<p><b>NOTE:</b> If PDF::Table finds that the table width needs to be increased to accommodate the requested text and formatting, it will output a warning. This could lead to undesired results. Possible solutions to keep the table from being widened include:</p>
<pre> 1) Increase table width (w)
2) Decrease font size (font_size)
3) Choose a narrower font
4) Decrease "max_word_length" parameter, so long words are split into
shorter chunks
5) Rotate media to landscape (if it is portrait)
6) Use a larger (wider) media size</pre>
<dt><a name="h_-_Height_of_the_table_on_the_initial_(current)_page."
><b>h</b> - Height of the table on the initial (current) page.</a></dt>
<dd>
<p>Think of this as the <i>maximum height</i> (Y dimension) of the start of the table on this page. This would be the current <code>Y</code> location less any bottom margin. Normally you would let as much as possible fit on the page, but it's possible that you might want to split the table at an earlier point, to put more on the next (spill) page.</p>
<p><b>Value:</b> can be any number satisfying <code>0 < h < PageHeight - Current Y position</code></p>
<p><b>Default:</b> No default value</p>
<pre> 'h' => 250,</pre>
<p><b>Deprecated name:</b> <i>start_h</i> (will go away in the future!)</p>
</dd>
</dl>
<h4><a class='u' href='#___top' title='click to go to top of document'
name="Optional_settings"
>Optional settings</a></h4>
<p>These are settings which are not absolutely necessary, although their use may result in a much more pleasing appearance for the table. They all have a "reasonable" default (or inheritance from another setting).</p>
<h4><a class='u' href='#___top' title='click to go to top of document'
name="Optional_Global_Settings"
>Optional Global Settings</a></h4>
<p>These settings apply only to the entire table, and cannot be used to specify cell, column, or row properties. A global setting may only occur once.</p>
<dl>
<dt><a name="next_h_-_Height_of_the_table_on_any_additional_page."
><b>next_h</b> - Height of the table on any additional page.</a></dt>
<dd>
<p>Think of this as the <i>maximum height</i> (Y dimension) of any overflow (spill) table portions on following pages. <i>It is highly recommended that you explicitly specify this setting as the full (body content) height of a page, rather than having PDF::Table try to figure out a good value and <b>give a warning</b>.</i></p>
<p><b>Value:</b> can be any number satisfying <code>0 < next_h < PageHeight - y</code></p>
<p>You need to leave a non-negative amount of space at the bottom of the page.</p>
<p><b>Default:</b> Media height * 80% (80% of the paper height) You will receive a warning if <code>next_h</code> is needed for a spill page and you did not provide it!</p>
<pre> 'next_h' => 700,</pre>
<dt><a name="next_y_-_Y_coordinate_of_upper_left_corner_of_the_table_at_any_additional_page."
><b>next_y</b> - Y coordinate of upper left corner of the table at any additional page.</a></dt>
<dd>
<p>Think of this as the starting <code>Y</code> position of any overflow (spill or continuation) table portions on following pages. <i>It is highly recommended that you explicitly specify this setting to be at the top of the body content of a page, rather than having PDF::Table try to figure out a good value and <b>give a warning</b>.</i></p>
<p><b>Value:</b> can be any number satisfying <code>0 < next_y < PageHeight</code></p>
<p><b>Default:</b> Media height * 90% (10% down from the top of the paper) You will receive a warning if <code>next_y</code> is needed for a spill page and you did not provide it!</p>
<pre> 'next_y' => 750,</pre>
<dt><a name="ink_-_Whether_to_actually_write_the_table,_or_to_measure_the_table_size"
><b>ink</b> - Whether to actually write the table, or to measure the table size</a></dt>
<dd>
<p>You may want to know how high (tall) the actual table will be, before making a decision whether to start the table on <i>this</i> page, or another (typically, the top of the <i>next</i> page). You might want to know if there is space for two or more small tables on this page, or where best to split a table (give an <code>h</code> value to avoid splitting a row). You may also decide to rearrange data rows, if this will make better use of available space.</p>
<p>The default <i>ink</i> value is <i>1</i> (to output to the PDF file). If set to <i>0</i>, only the height measurements (total, header, footer, each data row), in points, will be returned.</p>
<p><b>Notes:</b></p>
<p>1. No "footer" can currently be defined. Space is reserved in the output list for a possible future implementation.</p>
<p>2. No matter if the header is repeated on each page, only one instance will be returned in the heights list. Think of the table as fitting on a single page, no matter how long it is, so don't forget to add in the (repeated) header height for each expected page of output!</p>
<p>3. If you have exceptionally heavy (thick) top and bottom border lines, you might want to add in some extra height (half the thickness of each) to the overall height of the table, to account for this.</p>
<p><b>Value:</b> 0 (return height only) or 1 (actually write the table)</p>
<p><b>Default:</b> 1 (write out the table)</p>
<pre> 'ink' => 0,</pre>
<p><b>Caution:</b> Currently, <code>ink</code> is ignored for cells with <i>markup</i>; their content will be written out regardless of <code>ink</code>. We <i>do</i> plan to support <code>ink</code> for markup cells in the not-too-distant future.</p>
<dt><a name="size_-_Specified_column_widths."
><b>size</b> - Specified column widths.</a></dt>
<dd>
<p>The default behavior of PDF::Table is to calculate the width needed for each column, based on the longest word, content size, and optional minimum and maximum settings. As an alternative, you may give a string specifying the widths of all columns, one entry per column. An entry may be a fixed width (number and unit), or a relative width to be allocated from remaining space after the fixed width columns are removed from the table width.</p>
<p>If no unit is given, 'pt' (big points, 1/72 inch) are assumed. If no number is given, '1' is assumed (not recommended, except for '*'). The following units are supported:</p>
<dl>
<dt><a name="pt_-_points_(1/72_inch)"
><b>pt</b> - points (1/72 inch)</a></dt>
<dd>
<dt><a name="in_-_inches_(72_points)"
><b>in</b> - inches (72 points)</a></dt>
<dd>
<dt><a name="cm_-_centimeters_(28.3_points)"
><b>cm</b> - centimeters (28.3 points)</a></dt>
<dd>
<dt><a name="mm_-_millimeters_(2.83_points)"
><b>mm</b> - millimeters (2.83 points)</a></dt>
<dd>
<dt><a name="em_-_ems_(width_of_'M',_depends_on_table_default_font)"
><b>em</b> - ems (width of 'M', depends on table default font)</a></dt>
<dd>
<dt><a name="ex_-_exs_(width_of_'x',_depends_on_table_default_font)"
><b>ex</b> - exs (width of 'x', depends on table default font)</a></dt>
</dl>
<p>These are all absolute (fixed) sizes. If using font-dependent units (ems and exs), be aware of the overall font and font-size in use by PDF::Table (default is normally 12pt Times-Roman).</p>
<p>There are also relative or allocatable sizes, specified with the unit '*'. After all fixed-size columns have been processed, whatever table width that is left over will be distributed among the remaining (relative) columns proportional to the number for each column (e.g., <b>2*</b> gets twice the width that <b>*</b> gets).</p>
<p><b>Value:</b> a string containing one entry per column</p>
<p>Each entry is separated by one or more whitespaces (e.g., blanks). Numbers are unsigned (positive) and may be integers or real numbers (with decimal point). The unit follows immediately (no spaces between number and unit). Note that any column <i>minimum</i> or <i>maximum</i> width settings will be ignored!</p>
<p><b>Default:</b> None. If not given, widths will be calculated for the columns.</p>
<pre> 'size' => '* 3.5in 1.7* 4cm',</pre>
<dt><a
><b>new_page_func</b> - CODE reference to a function that returns a PDF::Builder::Page instance. See section <a href="#New_Page_Function_Hook" class="podlinkpod"
>"New Page Function Hook"</a> below.</a></dt>
<dd>
<pre> 'new_page_func' => $code_ref,</pre>
<dt><a
><b>cell_render_hook</b> - CODE reference to a function called with the current cell coordinates. See section <a href="#Cell_Render_Hook" class="podlinkpod"
>"Cell Render Hook"</a> below.</a></dt>
<dd>
<pre> 'cell_render_hook' => $code_ref,</pre>
<dt><a
><b>header_props</b> - HASH reference to specific settings for the Header row of the table. See section <a href="#Header_Row_Properties" class="podlinkpod"
>"Header Row Properties"</a> below.</a></dt>
<dd>
<pre> 'header_props' => $hdr_props,</pre>
<dt><a name="row_props_-_HASH_reference_to_specific_settings_for_each_row_of_the_table._See_section_"Row_Properties"_below."
><b>row_props</b> - HASH reference to specific settings for each row of the table. See section <a href="#Row_Properties" class="podlinkpod"
>"Row Properties"</a> below.</a></dt>
<dd>
<pre> 'row_props' => $my_row_props,</pre>
<dt><a name="column_props_-_HASH_reference_to_specific_settings_for_each_column_of_the_table._See_section_"Column_Properties"_below."
><b>column_props</b> - HASH reference to specific settings for each column of the table. See section <a href="#Column_Properties" class="podlinkpod"
>"Column Properties"</a> below.</a></dt>
<dd>
<pre> 'column_props' => $col_props,</pre>
<dt><a name="cell_props_-_HASH_reference_to_specific_settings_for_each_column_of_the_table._See_section_"Cell_Properties"_below."
><b>cell_props</b> - HASH reference to specific settings for each column of the table. See section <a href="#Cell_Properties" class="podlinkpod"
>"Cell Properties"</a> below.</a></dt>
<dd>
<pre> 'cell_props' => $cell_props,</pre>
<dt><a name="border_w_-_Width_of_table_border_lines."
><b>border_w</b> - Width of table border lines.</a></dt>
<dd>
<dt><a
><b>h_border_w</b> - Width of horizontal border lines (top and bottom of the table). Overrides 'border_w' value for horizontal usage. Note that if the table spills over onto following pages, only the very first top and very last bottom table border will be full width. Dividers on row boundaries will be 1pt wide ($border_w_default) solid lines, and where a row is divided within its content, a dashed (pattern $dashed_rule_default) 1pt wide line is used.</a></dt>
<dd>
<dt><a name="v_border_w_-_Width_of_vertical_border_lines._Overrides_'border_w'_value_for_vertical_usage."
><b>v_border_w</b> - Width of vertical border lines. Overrides 'border_w' value for vertical usage.</a></dt>
<dd>
<p><b>Value:</b> can be any positive number. When set to 0, it will disable border lines. This is the line thickness for drawing a border.</p>
<p><b>Default:</b> <code>1</code> ($border_w_default)</p>
<p>The <i>border</i> is the <b>outside</b> frame around the table. It does not enter into table height or width calculations, so be sure to set your <code>x</code> and <code>w</code> settings to allow for the width of vertical borders, and your <code>y</code> or <code>next_y</code> and <code>h</code> or <code>next_h</code> settings to allow for the width (thickness or height) of the horizontal borders, especially if you make them more than a Point or two in thickness (line width).</p>
<pre> 'border_w' => 3, # border width is 3
'h_border_w' => 1, # horizontal borders will be 1, overriding 3
'v_border_w' => undef, # vertical borders will be 3, as it will
# fall back to 'border_w'</pre>
<p>Note that both borders and rules overlay the exact boundary between two cells (i.e., the centerline). That is, one half of a rule or border will overlay the adjoining cells. Rules do not expand the size of the table, although borders will (by a total of their thickness/width). If you set particularly thick (wide) rules, pay attention to adding some padding on the appropriate side(s), so that valuable content is not overlaid. For cells along the outer border, one half the width of a border will overlay the cell, so account for this in the padding specification.</p>
<p><b>Deprecated names:</b> <i>border</i> (now 'border_w'), <i>horizontal_borders</i> (now 'h_border_w'), and <i>vertical_borders</i> (now 'v_border_w'); will go away in the future!</p>
<dt><a name="border_c_-_Border_color_for_all_borders."
><b>border_c</b> - Border color for all borders.</a></dt>
<dd>
<p><b>Value:</b> Color specifier as 'name' or '#rrggbb'</p>
<p><b>Default:</b> <code>'black'</code> ($fg_color_default)</p>
<pre> 'border_c' => 'red',</pre>
<p><b>Deprecated name:</b> <i>border_color</i> (will go away in the future!)</p>
<p>The same color is used for both the horizontal and vertical borders.</p>
</dd>
</dl>
<h4><a class='u' href='#___top' title='click to go to top of document'
name="Optional_Cell,_Column,_Row,_or_Global_Settings"
>Optional Cell, Column, Row, or Global Settings</a></h4>
<p>These settings can be specified to apply to the entire table, or more narrowly applied to the header row (in header_props hash), one or more rows (in row_props array), one or more columns (in column_props array), or one or more individual cells (in cell_props hash).</p>
<p>If a setting is specified in more than one place, the order of precedence is as follows: a header property (header row only), followed by a cell property, followed by a column property, followed by a row property, followed by a global setting, and finally, any hard-coded default value (if required).</p>
<p>A global setting may only occur once (although it may be overridden by cell, column, or row usage of the same setting).</p>
<dl>
<dt><a name="default_text_-_A_string_to_use_if_no_content_(text)_is_defined_for_a_cell."
><b>default_text</b> - A string to use if no content (text) is defined for a cell.</a></dt>
<dd>
<p>It is also used if a cell has exhausted its given text content, and has been split over a page break. This can happen if other cells in the row have much more text content than this cell. Therefore, it might be a good idea to <i>not</i> use a default such as "no cell content", as this could be confusing to readers who have seen content for this cell on the previous page.</p>
<p>Note that <code>max_word_length</code> splitting is <i>not</i> applied to the default text, so be careful about using long words.</p>
<p>If you want different effects for different rows, columns, or cells, you can override the global default setting. If you want <b>(No content)</b> for the first printout of a cell (split over two or more pages) and <b>-</b> for second and later printouts, you could leave the global default as '-' and simply give the cell the text "(No content)" (no longer really <i>empty</i>, but you get the idea). If you have some content for a cell, and want <b>no further entry</b> after it runs out of content, you could set <code>default_text</code> to <b>no further entry</b>, and so on.</p>
<p><b>Value:</b> any string (can be a blank ' ' or an empty string '').</p>
<p><b>Default:</b> '-' ($empty_cell_text)</p>
<dt><a name="max_word_length_-_Breaks_long_words"
><b>max_word_length</b> - Breaks long words</a></dt>
<dd>
<p>It may be necessary to break up long words (like serial numbers, hashes, etc.) to fit within a column, by adding a space after every Nth symbol, unless a space (x20) is found already in the text.</p>
<p><b>Note</b> that this does <i>not</i> add a hyphen (dash)! It merely ensures that there will be no runs of non-space characters longer than <i>N</i> characters, reducing the chance of forcing an overly wide column.</p>
<p><b>Value:</b> can be any positive integer number (character count)</p>
<p><b>Default:</b> <code>20</code></p>
<pre> 'max_word_length' => 25, # Will add a space after every 25 symbols
# unless there is a natural break (space)</pre>
<dt><a name="padding_-_Padding_applied_to_every_cell"
><b>padding</b> - Padding applied to every cell</a></dt>
<dd>
<dt><a name="padding_top_-_top_cell_padding,_overrides_'padding'"
><b>padding_top</b> - top cell padding, overrides 'padding'</a></dt>
<dd>
<dt><a name="padding_right_-_right_cell_padding,_overrides_'padding'"
><b>padding_right</b> - right cell padding, overrides 'padding'</a></dt>
<dd>
<dt><a name="padding_left_-_left_cell_padding,_overrides_'padding'"
><b>padding_left</b> - left cell padding, overrides 'padding'</a></dt>
<dd>
<dt><a name="padding_bottom_-_bottom_padding,_overrides_'padding'"
><b>padding_bottom</b> - bottom padding, overrides 'padding'</a></dt>
<dd>
<p><b>Value:</b> can be any non-negative number (≥ 0)</p>
<p><b>Default padding:</b> <code>2</code>. ($padding_default)</p>
<p>See <a href="#COMPATIBILITY" class="podlinkpod"
>"COMPATIBILITY"</a> for returning to the old value of <code>0</code>.</p>
<p><b>Default padding_*</b> <code>'padding'</code></p>
<pre> 'padding' => 5, # all sides cell padding
'padding_top' => 8, # top cell padding, overrides 'padding'
'padding_right' => 6, # right cell padding, overrides 'padding'
'padding_left' => 2, # left cell padding, overrides 'padding'
'padding_bottom' => undef, # bottom padding will be 5, as it will fall
# back to 'padding' value</pre>
<dt><a name="font_-_instance_of_PDF::Builder::Resource::Font_defining_the_font_to_be_used_in_the_table_(or_a_subsection_of_it)."
><b>font</b> - instance of PDF::Builder::Resource::Font defining the font to be used in the table (or a subsection of it).</a></dt>
<dd>
<p><b>Value:</b> can be any PDF::Builder::Resource::* type of font</p>
<p><b>Default:</b> <code>'Times'</code> core font with <i>latin1</i> encoding</p>
<pre> 'font' => $pdf->corefont("Helvetica", -encoding => "latin1"),</pre>
<p><b>CAUTION:</b> Only TrueType and OpenType fonts (ttfont call) can make use of multibyte encodings such as 'utf8'. Errors will result if you attempt to use 'utf8', etc. with corefont, psfont, etc. font types! For these, you <i>must</i> only specify a single-byte encoding.</p>
<dt><a name="font_size_-_Size_of_the_font_that_will_be_used_in_the_table_(or_a_subsection_of_it)."
><b>font_size</b> - Size of the font that will be used in the table (or a subsection of it).</a></dt>
<dd>
<p><b>Value:</b> can be any positive number</p>
<p><b>Default:</b> <code>12</code> ($font_size_default)</p>
<pre> 'font_size' => 16,</pre>
<dt><a name="fg_color_-_Font_color_for_all_text."
><b>fg_color</b> - Font color for all text.</a></dt>
<dd>
<dt><a name="bg_color_-_Background_color_for_all_text."
><b>bg_color</b> - Background color for all text.</a></dt>
<dd>
<p><b>Value:</b> Color specifier as 'name' or '#rrggbb' (or other suitable color specification format)</p>
<p><b>Default:</b> <code>'black'</code> text on (transparent) background. In other words, there is no default background color. The exception is for any <b>header</b> row, where the default colors are <code>#000066</code> (dark blue, $h_fg_color_default) on <code>#FFFFAA</code> (light yellow, $h_bg_color_default).</p>
<pre> 'fg_color' => '#333333',</pre>
<p><b>Deprecated names:</b> <i>font_color, background_color</i> (both will go away in the future!)</p>
<dt><a name="fg_color_odd_-_Font_color_for_odd_rows_(override_fg_color)."
><b>fg_color_odd</b> - Font color for odd rows (override <code>fg_color</code>).</a></dt>
<dd>
<dt><a name="fg_color_even_-_Font_color_for_even_rows_(override_fg_color)."
><b>fg_color_even</b> - Font color for even rows (override <code>fg_color</code>).</a></dt>
<dd>
<dt><a name="bg_color_odd_-_Background_color_for_odd_rows_(override_bg_color)."
><b>bg_color_odd</b> - Background color for odd rows (override <code>bg_color</code>).</a></dt>
<dd>
<dt><a name="bg_color_even_-_Background_color_for_even_rows_(override_bg_color)."
><b>bg_color_even</b> - Background color for even rows (override <code>bg_color</code>).</a></dt>
<dd>
<p><b>Value:</b> Color specifier as 'name' or '#rrggbb' (or other suitable color specification format)</p>
<pre> 'fg_color_odd' => 'purple',
'fg_color_even' => '#00FF00',
'bg_color_odd' => 'gray',
'bg_color_even' => 'lightblue',</pre>
<p><b>Deprecated names:</b> <i>font_color_odd, font_color_even, background_color_odd, background_color_even</i> (all will go away in the future!)</p>
<p>Note that *_color_odd/even usually make the most sense as global settings, although it <i>is</i> possible to use them within columns (see chess.pl example), and even rows and cells, but not header rows.</p>
<dt><a name="underline_-_Underline_specifications_for_text_in_the_table."
><b>underline</b> - Underline specifications for text in the table.</a></dt>
<dd>
<p><b>Value:</b> 'auto', integer of distance (below baseline), or arrayref of distance & thickness (more than one pair will provide multiple underlines). Negative distance gives strike-through. <code>[]</code> ('none' also works for PDF::Builder) gives no underline.</p>
<p>Note that it is unwise to underline all content in the table! It should be used selectively to <i>emphasize</i> important text, such as header content, or certain cells. Unfortunately, there is currently no way to turn underlining off and on <i>within</i> a cell.</p>
<p><b>Default:</b> none</p>
<p><b>Deprecated name:</b> <i>font_underline</i> (will go away in the future!)</p>
<dt><a name="min_rh_-_Desired_minimum_row_height."
><b>min_rh</b> - Desired minimum row height.</a></dt>
<dd>
<p>This setting will be honored only if <code>min_rh > font_size + padding_top + padding_bottom</code> (i.e., it is taller than the calculated minimum value).</p>
<p>This setting doesn't usually make sense when used in a column_props or a cell_props, but it <i>is</i> possible to do, and may be useful in certain situations.</p>
<p><b>Value:</b> can be any positive number</p>
<p><b>Default:</b> <code>font_size + padding_top + padding_bottom</code></p>
<pre> 'min_rh' => 24,</pre>
<p><b>Deprecated name:</b> <i>row_height</i> (will go away in the future!)</p>
<dt><a name="justify_-_Alignment_of_text_in_a_cell."
><b>justify</b> - Alignment of text in a cell.</a></dt>
<dd>
<p><b>Value:</b> One of 'left', 'right', 'center'</p>
<p><b>Default:</b> <code>'left'</code></p>
<dt><a name="min_w_-_Minimum_width_of_this_cell_or_column."
><b>min_w</b> - Minimum width of this cell or column.</a></dt>
<dd>
<p>PDF::Table will set a cell (and the column it's in) minimum width to fit the longest word (after splitting on <code>max_word_length</code>) found in the text. This amount may be increased to <code>min_w</code>. A column should be no narrower than its widest minimum width, but could be larger in order to fill out the table width.</p>
<p><b>Value:</b> can be any number satisfying <code>0 < min_w < w</code></p>
<p><b>Default:</b> Auto calculated</p>
<p>Note that <code>min_w</code> is usually used for a column_props to set the column minimum width. If used in a row_props, it will act as a <i>global</i> setting; if used in a cell_props, that will force the minimum width for the cell's column.</p>
<dt><a name="max_w_-_Maximum_width_of_this_column."
><b>max_w</b> - Maximum width of this column.</a></dt>
<dd>
<p>PDF::Table will set a cell (and the column it's in) maximum width to fit the total length of the text content. This will seldom be actually used, but <code>max_w</code> may be used to <i>reduce</i> this maximum. When columns are being widened in order to meet the desired table width, it will try to honor the maximum width setting and avoid adding any width to a column already at its maximum width (but this cannot be guaranteed).</p>
<p><b>Value:</b> can be any number satisfying <code>0 < min_w ≤ max_w < w</code></p>
<p><b>Default:</b> Auto calculated</p>
<dt><a name="rule_w_-_Width_of_table_rule_lines_(internal_table_dividers)."
><b>rule_w</b> - Width of table rule lines (internal table dividers).</a></dt>
<dd>
<dt><a name="h_rule_w_-_Width_of_horizontal_rules_(bottom_of_a_cell)._Overrides_'rule_w'_value_for_horizontal_usage."
><b>h_rule_w</b> - Width of horizontal rules (bottom of a cell). Overrides 'rule_w' value for horizontal usage.</a></dt>
<dd>
<dt><a name="v_rule_w_-_Width_of_vertical_rules_(left_side_of_a_cell)._Overrides_'rule_w'_value_for_vertical_usage."
><b>v_rule_w</b> - Width of vertical rules (left side of a cell). Overrides 'rule_w' value for vertical usage.</a></dt>
<dd>
<p><b>Value:</b> can be any positive number. When set to 0, it will disable rules. This is the line thickness for drawing a rule.</p>
<p><b>Default:</b> <code>1</code> (corresponding border value)</p>
<p>A <i>rule</i> is a line bordering a <i>cell</i> in the table. While it does not enter into table height or width calculations, be sure to set your <code>padding</code> settings to allow sufficient clearance of cell content, especially if you make the rules more than a Point or two in thickness (line width). Note that a cell only defines and draws its left and bottom rules -- the top rule is defined in the cell or row above, and the right rule is defined in the cell or column to the right of this one.</p>
<pre> 'rule_w' => 3, # rule width is 3
'h_rule_w' => 1, # horizontal rules will be 1, overriding 3
'v_rule_w' => undef, # vertical rules will be 3, as it will
# fall back to 'rule_w'</pre>
<p>Note that both borders and rules overlay the exact boundary between two cells (i.e., the centerline). That is, one half of a rule or border will overlay the adjoining cells. Rules do not expand the size of the table. If you set particularly thick (wide) rules, pay attention to adding some padding on the appropriate side(s), so that valuable content is not overlaid. For cells along the outer border, a <i>border</i> will be drawn instead of a <i>rule</i>.</p>
<p>Cell rules inherit thickness and color from the border settings, so if you want no internal rules, you need to set</p>
<pre> 'rule_w' => 0, # no rules</pre>
<dt><a name="rule_c_-_Rule_color_for_all_rules."
><b>rule_c</b> - Rule color for all rules.</a></dt>
<dd>
<dt><a name="h_rule_c_-_Rule_color_for_horizontal_(bottom)_rules,_overriding_rule_c_for_this_usage."
><b>h_rule_c</b> - Rule color for horizontal (bottom) rules, overriding <code>rule_c</code> for this usage.</a></dt>
<dd>
<dt><a name="v_rule_c_-_Rule_color_for_vertical_(left)_rules,_overriding_rule_c_for_this_usage."
><b>v_rule_c</b> - Rule color for vertical (left) rules, overriding <code>rule_c</code> for this usage.</a></dt>
<dd>
<p><b>Value:</b> Color specifier as 'name' or '#rrggbb'</p>
<p><b>Default:</b> <code>'black'</code> (corresponding border value)</p>
<pre> 'rule_c' => 'red',</pre>
</dd>
</dl>
<h4><a class='u' href='#___top' title='click to go to top of document'
name="New_Page_Function_Hook"
>New Page Function Hook</a></h4>
<p><b>new_page_func</b> is a CODE reference to a function that returns a PDF::Builder::Page instance.</p>
<p>If used, the parameter '<code>new_page_func</code>' must be a function reference which, when executed, will create a new page and will return the object to the module. For example, you can use it to put Page Title, Page Frame, Page Numbers and other content that you need. Also if you need a different paper size and orientation than the default US-Letter, e.g., B2-Landscape, you can use this function ref to set it up for you. For more info about creating pages, refer to PDF::Builder PAGE METHODS Section. Don't forget that your function must return a page object created with the PDF::Builder page() method. <code>$code_ref</code> can be something like <code>\&new_page</code>.</p>
<pre> 'new_page_func' => $code_ref,</pre>
<p>The <code>$code_ref</code> may be an inline sub definition (as show below), or a regular named <code>sub</code> (e.g., 'new_page()') referenced as <code>\&new_page</code>. The latter may be cleaner than inlining, if the routine is quite long.</p>
<p>An example of reusing a saved PDF page as a <i>template</i>:</p>
<pre> my $pdf = PDF::API2->new();
my $template = PDF::API2->open('pdf/template.pdf');
my $new_page_func = sub { return $pdf->import_page($template, 1); }
table(
...
new_page_func => $new_page_func,
...</pre>
<p>This will call a function to grab a copy of a template PDF's page 1 and insert it as the new last page of the PDF, as the starting point for the next <i>overflow</i> (continuation) page of the table, if needed. Note that the <code>$template->openpage(1)</code> call is <b>unsuitable</b> for this purpose, as it does not insert the page into the current PDF.</p>
<p>You can also create a blank page and prefill it with desired content:</p>
<pre> my $pdf = PDF::API2->new();
my $new_page_func = sub {
my $page = $pdf->page(); # so far, no difference from default behavior
$page->mediaBox(...); # set page size/orientation, etc.
my $text = $page->text();
# set font, placement, etc.
$text->text(...); # write header, footer, etc.
...
return $page;
}
table(
...
new_page_func => $new_page_func,
...</pre>
<p>If <code>new_page_func</code> is not defined, PDF::Table will simply call <code>$pdf->page()</code> to generate a new, blank, "next" page.</p>
<p>Note that this function is <b>not</b> called for the first page of a table. That one uses the current <code>$page</code> parameter passed to the <code>table()</code> call. It is only called when needed for overflow (<code>next_y</code> and <code>next_h</code>) pages, where it replaces the <code>$page</code> parameter with a new page framework. You may want to consider using the same function to create your other (non-table) pages, assuming you want the same format (PDF content) across all pages of the table.</p>
<h4><a class='u' href='#___top' title='click to go to top of document'
name="Cell_Render_Hook"
>Cell Render Hook</a></h4>
<p><b>cell_render_hook</b> is a CODE reference to a function called with the current cell coordinates. If used, the parameter <code>cell_render_hook</code> must be a function reference. It is most useful for creating special items within a text block, such as a URL link inside of a cell. The following example adds a link in the first column of each non-header row:</p>
<pre> 'cell_render_hook' => sub {
my ($page, $first_row, $row, $col, $x, $y, $w, $h) = @_;
# Do nothing except for first column (and not a header row)
return unless ($col == 0);
return if ($first_row);
# Create link
my $value = $list_of_vals[$row-1];
my $url = "https://${hostname}/app/${value}";
my $annot = $page->annotation();
$annot->url( $url, -rect => [$x, $y, $x+$w, $y+$h] );
},</pre>
<h4><a class='u' href='#___top' title='click to go to top of document'
name="Header_Row_Properties"
>Header Row Properties</a></h4>
<p>If the 'header_props' parameter is used, it should be a hashref. Passing an empty HASH will trigger a header row initialized with Default values. There is no 'data' variable for the content, because the module assumes that the first table row will become the header row. It will copy this row and put it on every new page if the 'repeat' parameter is set.</p>
<dl>
<dt><a name="repeat_-_Flag_showing_if_header_row_should_be_repeated_on_every_new_page."
><b>repeat</b> - Flag showing if header row should be repeated on every new page.</a></dt>
<dd>
<p><b>Value:</b> 0,1 1-Yes/True, 0-No/False</p>
<p><b>Default:</b> <code>1</code> ($repeat_default)</p>
<p>See <a href="#COMPATIBILITY" class="podlinkpod"
>"COMPATIBILITY"</a> if you wish to change it back to the old behavior of <code>0</code>.</p>
<pre> my $hdr_props = {
'font' => $pdf->corefont("Helvetica", -encoding => "latin1"),
'font_size' => 18,
'fg_color' => '#004444',
'bg_color' => 'yellow',
'repeat' => 0,
'justify' => 'center',
};</pre>
</dd>
</dl>
<h4><a class='u' href='#___top' title='click to go to top of document'
name="Row_Properties"
>Row Properties</a></h4>
<p>If the 'row_props' parameter is used, it should be an arrayref of hashrefs, with one hashref for each row of the table. The rows are counted from top to bottom, so the hash reference at <code>$row_props[0]</code> will hold properties for the first row (from top to bottom). If you DO NOT want to give properties for a row, but to give for another, just insert an empty hash reference into the array for the row that you want to skip. This will cause the counting to proceed as expected and the properties to be applied at the right rows.</p>
<p>Each hashref can contain any of the keys shown below:</p>
<blockquote>
<p>Example:</p>
<pre> my $row_props = [
# This is an empty hash to indicate default properties for first row
{},
# the next hash will hold the properties for the second row from
# top to bottom.
{
'min_rh' => 75, # Minimum row height of 75
'justify' => 'right', # Right text alignment
'font' => $pdf->corefont("Helvetica",
-encoding => "latin1"),
'font_size' => 10,
'fg_color' => 'blue',
'bg_color' => '#FFFF00',
},
# etc.
];</pre>
<p>There are no settings unique to rows. Do be aware of when "row 0" may refer to <i>header</i> row properties!</p>
</blockquote>
<h4><a class='u' href='#___top' title='click to go to top of document'
name="Column_Properties"
>Column Properties</a></h4>
<p>If the 'column_props' parameter is used, it should be an arrayref of hashrefs, with one hashref for each column of the table. The columns are counted from left to right, so the hash reference at <code>$col_props[0]</code> will hold properties for the first column (from left to right). If you DO NOT want to give properties for a column, but to give for another, just insert an empty hash reference into the array for the column that you want to skip. This will cause the counting to proceed as expected and the properties to be applied at the right columns.</p>
<p>Each hashref can contain any of the keys shown below:</p>
<blockquote>
<p>Example:</p>
<pre> my $col_props = [
# This is an empty hash to indicate default properties for first col.
{},
# the next hash will hold the properties for the second column from
# left to right.
{
'min_w' => 100, # Minimum column width of 100
'max_w' => 150, # Maximum column width of 150
'justify' => 'right', # Right text alignment
'font' => $pdf->corefont("Helvetica",
-encoding => "latin1"),
'font_size' => 10,
'fg_color' => 'blue',
'bg_color' => '#FFFF00',
},
# etc.
];</pre>
<p>There are no settings unique to columns.</p>
</blockquote>
<p>NOTE: If 'min_w' and/or 'max_w' parameter is used in 'col_props', keep in mind that it may be overridden by the calculated minimum/maximum cell width so that the table can be created. When this happens, a warning will be issued with some suggestions on what can be done. In cases of a conflict between column formatting and odd/even row formatting, 'col_props' will override odd/even.</p>
<h4><a class='u' href='#___top' title='click to go to top of document'
name="Cell_Properties"
>Cell Properties</a></h4>
<p>If the 'cell_props' parameter is used, it should be an arrayref with arrays of hashrefs (of the same dimension as the data array) with one hashref for each cell of the table.</p>
<p>Each hashref can contain any of the keys shown below:</p>
<dl>
<dt><a name="colspan_-_Span_this_cell_over_multiple_columns_to_the_right."
><b>colspan</b> - Span this cell over multiple columns to the right.</a></dt>
<dd>
<p><b>Value:</b> can be any positive number less than the number of columns to the right of the current column</p>
<p><b>Default:</b> undef</p>
<p>NOTE: If you want to have regular columns <b>after</b> a colspan, you have to provide <code>undef</code> for the columns that should be spanned</p>
<p>NOTE: If you use <code>colspan</code> to span a column, but provide data for it, your table will be mangled: the spanned-but-data-provided-column will be rendered! But, as HTML works the same way, we do not consider this a bug.</p>
<p>Example:</p>
<pre> # row0 col1 should span 2 cols:
@data = ( [ 'r1c1', 'r1c2', 'r1c3' ], ['r2c1+',undef,'r2c3'] );
# note: ignoring return values array
$tab->table( $pdf, $page, \@data, %TestData::required,
'cell_props' => [
[],
[{'colspan' => 2}]
]
);</pre>
</dd>
</dl>
<p>See the file <code>examples/colspan.pl</code> for detailed usage.</p>
<p>Example:</p>
<pre> my $cell_props = [
[ # This array is for the first row (0).
# If header_props is defined, it will override these settings.
{ # Row 0 cell 0
'bg_color' => '#AAAA00',
'fg_color' => 'yellow',
'underline' => [ 2, 2 ],
},
# etc.
],
[ # Row 1 (first data row, if header_props given)
{ # Row 1 cell 0
'bg_color' => '#CCCC00',
'fg_color' => 'blue',
},
{ # Row 1 cell 1
'bg_color' => '#BBBB00',
'fg_color' => 'red',
},
# etc.
],
[ # Row 2
{ # Row 2 cell 0 span cell 1
'colspan' => 2
},
# etc.
],
# etc.
];
OR
my $cell_props = [];
$cell_props->[1][0] = {
# Row 2 cell 1
'bg_color' => '#CCCC00',
'fg_color' => 'blue',
};</pre>
<h2><a class='u' href='#___top' title='click to go to top of document'
name="text_block()"
>text_block()</a></h2>
<pre> my ($width_of_last_line, $ypos_of_last_line, $left_over_text) =
text_block( $txt, $data, %settings)</pre>
<dl>
<dt><a name="Description"
>Description</a></dt>
<dd>
<p>Utility method to create a block of text. The block may contain multiple paragraphs (input <code>$data</code> separated by implicit or explicit newlines <code>\n</code>). It is mainly used internally, but you can use it from outside for placing formatted text anywhere on the sheet.</p>
<p>NOTE: This method will NOT add more pages to the PDF instance if the space is not enough to place the string inside the block. Leftover text will be returned and has to be handled by the caller - i.e., add a new page and a new block with the leftover.</p>
<dt><a name="Parameters"
>Parameters</a></dt>
<dd>
<pre> $txt - a PDF::Builder::Page::Text instance representing the text tool.
$data - a string that will be placed inside the block, broken up into
lines that fit within the indicated width.
%settings - HASH with geometry and formatting parameters. Note that
several parameters are mandatory.</pre>
<dt><a name="Returns"
>Returns</a></dt>
<dd>
<p>The return value is a 3 item list where</p>
<pre> $width_of_last_line - Width of last line in the block
$final_y - The Y coordinate of the block bottom so that additional
content can be added after it
$left_over_text - Text that did not fit in the provided box geometry.</pre>
<dt><a name="Example"
>Example</a></dt>
<dd>
<pre> # PDF::Builder objects
my $page = $pdf->page();
my $txt = $page->text();
my %settings = (
# MANDATORY position and table size
'x' => 10,
'y' => 570,
'w' => 220,
'h' => 180,
# OPTIONAL PARAMETERS
'leading' => $font_size*1.15 | $distance_between_lines,
'align' => "left|right|center|justify|fulljustify",
default: left
'max_word_length' => $optional_max_word_chars_between_splits
default: 20
'parspace' => $optional_vertical_space_before_paragraph,
default: 0 extra vertical space
# Only one of the following parameters can be given.
# They override each other, in the order given. C<hang> is the
# highest weight.
'hang' => $optional_hanging_text_to_lead_a_paragraph,
'flindent' => $optional_indent_of_first_line,
'fpindent' => $optional_indent_of_first_paragraph,
'indent' => $optional_indent_of_text_to_every_non_first_line,
);
my ( $width_of_last_line, $final_y, $left_over_text ) =
$pdftable->text_block( $txt, $data, %settings );</pre>
</dd>
</dl>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="VERSION"
>VERSION</a></h1>
<p>1.005</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="AUTHOR"
>AUTHOR</a></h1>
<p>Daemmon Hughes</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="DEVELOPMENT"
>DEVELOPMENT</a></h1>
<p>Further development Versions 0.02 -- 0.11 - Desislav Kamenov</p>
<p>Further development since Ver: 0.12 - Phil Perry</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="COPYRIGHT_AND_LICENSE"
>COPYRIGHT AND LICENSE</a></h1>
<p>Copyright (C) 2006 by Daemmon Hughes, portions Copyright (C) 2004 Stone Environmental Inc. (www.stone-env.com) All Rights Reserved.</p>
<p>Copyright (C) 2020-2024 by Phil M Perry.</p>
<p>This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available. Note that Perl 5.10 is the minimum supported level.</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="PLUGS"
>PLUGS</a></h1>
<dl>
<dt><a name="by_Daemmon_Hughes"
>by Daemmon Hughes</a></dt>
<dd>
<p>Much of the original development work on this module was sponsored by Stone Environmental Inc. (www.stone-env.com).</p>
<p>The text_block() method is a slightly modified copy of the one from Rick Measham's PDF::API2 tutorial at http://pdfapi2.sourceforge.net/cgi-bin/view/Main/YourFirstDocument</p>
<dt><a name="by_Desislav_Kamenov_(@deskata_on_Twitter)"
>by Desislav Kamenov (@deskata on Twitter)</a></dt>
<dd>
<p>The development of this module was supported by SEEBURGER AG (www.seeburger.com) till year 2007</p>
<p>Thanks to my friends Krasimir Berov and Alex Kantchev for helpful tips and QA during development of versions 0.9.0 to 0.9.5</p>
<p>Thanks to all GitHub contributors!</p>
</dd>
</dl>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="CONTRIBUTION"
>CONTRIBUTION</a></h1>
<p>PDF::Table is on GitHub. You are more than welcome to contribute!</p>
<p>https://github.com/PhilterPaper/PDF-Table</p>
<h1><a class='u' href='#___top' title='click to go to top of document'
name="SEE_ALSO"
>SEE ALSO</a></h1>
<p><a href="https://metacpan.org/pod/PDF%3A%3AAPI2" class="podlinkpod"
>PDF::API2</a>, <a href="https://metacpan.org/pod/PDF%3A%3ABuilder" class="podlinkpod"
>PDF::Builder</a></p>
<!-- end doc -->
</body></html>
|