2015-10-16 20 views
0

任務:添加一些數據(比如本地時間)以PDF文件(此PDF文件包含的形式)使用Perl的Javascript的增強表單處理PDF文件

示例文件:http://www.immihelp.com/nri/forms/passport-application-form.pdf

我有迄今爲止嘗試了3個流行模塊。 PDF::API2,CAM::PDFPDF::Reuse

嘗試1:PDF::API2

#!/usr/bin/perl 
use strict; 
use warnings; 
use PDF::API2; 
my $pdf = PDF::API2->open('form.pdf'); 

Error: The PDF file uses a cross-reference stream, which is not yet supported (see Know n Issues in the PDF::API2 documentation) at C:\Perl\site\lib/PDF/API2/Basic/PDF/ File.pm line 1048.

嘗試2:CAM::PDF

#!/usr/bin/perl 
use strict; 
use warnings; 
use Data::Dump qw(dump); 
use CAM::PDF; 
my $pdf = CAM::PDF->new('form.pdf') or die "failed"; 
$pdf->appendPageContent(1, localtime); 
$pdf->save(); 

Error: This stream is too complex for me to write... Giving up

我檢查了代碼,發現這個模塊不支持複雜小號此刻

From PDF.pm

# TODO: Handle more complex streams ... 
die "This stream is too complex for me to write... Giving up\n"; 

當我試圖cleanoutput方法,而不是save treams它工作正常,但打開PDF我得到的消息之下。我還觀察到,現在我無法將數據輸入到表單中。

完整映像網址:http://i.stack.imgur.com/anAMW.png

enter image description here

嘗試3:PDF::Reuse

#!/usr/bin/perl 
use strict; 
use warnings; 
use PDF::Reuse; 
prFile('output.pdf'); 
prForm("form.pdf"); 
prPage(); 
prText(100,100, localtime); 
prEnd(); 

問題:上面代碼中正確添加數據,但是第2頁的原始PDF是沒有更多可用於output.pdf

我注意到Merlyn(Randal L Schwartz)也問過perlmonks上的類似問題(http://www.perlmonks.org/?node_id=556764)。

回答

0
#!/usr/bin/perl 

use strict; 
use warnings; 
use PDF::Reuse; 

prFile('output.pdf'); 

my $left_page = 1; 
my $page_number = 1; 

while ($left_page) { 
    prForm("form.pdf", $page_number); 
    # Fill data 
    prText(100, 100, localtime) if $page_number == 1; 

    $left_page = prSinglePage("form.pdf"); 
    $page_number ++ 
} 

prEnd();