用Perl创建包含标题、文本和表格的PDF报告
我正在尝试创建具有以下要求的报告:用Perl创建包含标题、文本和表格的PDF报告,perl,pdf,report,Perl,Pdf,Report,我正在尝试创建具有以下要求的报告: 每一页都有标题(比如作者姓名、报告日期) 然后会有一些描述文档的文本(例如设备名称、ip等) 然后会有一个只有几页的表格 我的问题是,每当我结合第2步和第3步时,每一步都是单独的一页。我希望表格正好在课文之后 我尝试了PDF::API2、PDF::Table和PDF:Reuse(将这两部分结合起来) 但它们中的每一个都出现在单独的页面上。 有什么建议吗 代码如下: 使用PDF::API2; 使用PDF::Table; 使用PDF::重用 my $pdftabl
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();
只要我的2美分
重新考虑代码中的以下内容:
# Open an existing PDF file
$pdf = new PDF::API2(-file => "2.pdf");
$page = $pdf->page;
您不打算“打开现有的PDF”,而是要定义保存PDF的位置(实际保存是另一项任务)
然后你就给它添加了一个新的页面。注意:每次调用$pdf->page
时,您都会在pdf中添加一个新的空白页
因此,请继续使用已经定义的
$page
并继续使用PDF::Table。LaTeX(PDF-,Xe-)是否有效?这也是我的建议<代码>\usepackage{longtable}并使用LaTeX::Driver构建它。我已经在生产中使用PDF::API2和PDF::Table在同一页上。显示一些代码,也许我可以帮你。我已经添加了代码…如果你能看一下的话。谢谢,谢谢。这很有帮助。关键的想法是,你需要在表格后面(在同一页中)写下文本,然后只需播放Y,H,它就会出现在表格前面。