我正在尝试创建具有以下要求的报告:
- 每页都有标题(例如作者姓名,报告日期)。
- 然后会有一些描述文档的文本(例如设备名称、IP 等)
- 然后会有一个只有几页的表格。
我遇到的问题是,每当我结合第 2 步和第 3 步时,每一个都是单独的页面。我希望表格就在文本之后。
我已经尝试过 PDF::API2、PDF::Table 和 PDF:Reuse(将这两个部分结合起来)。
它们中的每一个仍然出现在单独的页面上。有什么建议么?
这是代码:使用 PDF::API2;使用 PDF::Table;使用 PDF::重用;
my $pdftable = new PDF::Table;
my $pdf = new PDF::API2(-file => "1.pdf");
my $page = $pdf->page;
$hdr_props =
{
# This param could be a pdf core font or user specified TTF.
# See PDF::API2 FONT METHODS for more information
font => $pdf->corefont("Times", -encoding => "utf8"),
font_size => 10,
font_color => '#006666',
bg_color => 'gray',
repeat => 1, # 1/0 eq On/Off if the header row should be repeated to every new page
};
# some data to layout
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."],
["Nulla euismod sem eget neque.",
"Donec odio neque",
"Sed eu velit."],
["Nulla euismod sem eget neque.",
"Donec odio neque",
"Sed eu velit."],
["Nulla euismod sem eget neque.",
"Donec odio neque",
"Sed eu velit."],
#... and so on
];
$left_edge_of_table = 50;
# build the table layout
$pdftable->table(
# required params
$pdf,
$page,
$some_data,
x => $left_edge_of_table,
w => 495,
start_y => 750,
next_y => 700,
start_h => 300,
next_h => 500,
# some optional params
padding => 5,
padding_right => 10,
background_color_odd => shift @_ || "#FFFFFF",
background_color_even => shift @_ || "#FFFFCC", #cell background color for even rows
header_props => $hdr_props, # see section HEADER ROW PROPERTIES
);
$pdf->saveas();
# Open an existing PDF file
$pdf = new PDF::API2(-file => "2.pdf");
$page = $pdf->page;
# Add a built-in font to the PDF
$font = $pdf->corefont('Helvetica-Bold');
# Add some text to the page
$text = $page->text();
$text->font($font, 20);
$text->translate(200, 700);
text->text('Hello World!');
# Save the PDF
$pdf->saveas();
prFile("report.pdf");
prDoc("2.pdf");
prDoc("1.pdf");
prEnd();