2010-12-16 48 views
1

我試圖在PDF中使用PDF :: Table在perl中創建PDF格式的表。 但是,它似乎沒有讀取我的標題/ cols /行設置。pdf :: table perl中的設置

這裏是我的表碼:

use PDF::API2; 
    use PDF::Table; 

    my $pdftable = new PDF::Table; 
    my $pdf = PDF::API2->new(); 
    my $page = $pdf->page; 
    #data 
    my $some_data =[ 
    ["1","1","1","1","1","1","1"], 
    ["2","2","2","2","2","2","2"], 
    ["2","2","2","2","2","2","2"], 
    ["2","2","2","2","2","2","2"], 
    ["2","2","2","2","2","2","2"],# x 100 time to have pages 
    ]; 

    #build the table layout 
    $pdftable->table(
    $pdf, 
    $page, 
    $some_data, 
    x => 5, 
    w => 600, 
    start_y => 750, 
    next_y => 750, 
    start_h => 700, 
    next_h => 700, 
    # some optional params 
    font_size => 8, 
    border => 0, 
    background_color_odd => "white", 
    background_color_even => "lightblue", 
    header_props => $hdr_props, # see section HEADER ROW PROPERTIES 
    ); 

    $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 => 'yellow', 
      repeat  => 1, # 1/0 eq On/Off if the header row should be repeated to every new page 
     }; 
print "Content-Type: application/pdf;\n\n"; 
binmode(STDOUT); 
print $pdf->stringify; 

應該作出缺席的第一行作爲標題,但輸出沒有顯示出頭部屬性被第一行設置。並且沒有顯示所有頁面的標題。

任何幫助將不勝感激。

+0

當你添加'use strict;使用警告;'頂部? – Ether 2010-12-16 19:31:05

回答

1

我沒有運行你的代碼。

在變量填充之前,您正在引用$hdr_props。 Perl不能這樣工作,你需要正確地定義定義。

use strict; use warnings FATAL => 'all';添加到程序的頂部,Perl會提醒您有關這樣的錯誤。

0

theres沒有任何警告,我遵循daxim把$ hdr_props放在首位,但它仍然不會在標題設置中讀取。

0

文檔說header_props需要一個散列引用,因此:

header_props => \$hdr_props, # see section HEADER ROW PROPERTIES 

我遇到了類似的問題。但是,daxim是正確的,您還應該按照他的建議訂購代碼。