由wkhtmltopdf创建的pdf的每个页面中的表头

时间:2015-02-03 10:14:15

标签: javascript perl pdf

我正在使用wkhtmltopdf-amd64创建pdf。我发送一个字符串,这是一个javascript中的表到这个perl文件.Pdf是正确创建的,但问题是在第二页和其他页面我也想要表头。这是我的perl程序。请帮助....

#!/usr/bin/perl
use CGI;
use CGI qw/param/;  
use URI::Escape; 
use strict;
use Data::Dumper;
use User;
use ADMIN;
use WORKFLOW;
use Time::Piece;
use User;
use HTML::Entities;
use lib "../utils";

use lib "../cgi";
use CGI::Carp qw(fatalsToBrowser);
use Date::Calc qw(:all);
use POSIX 'strftime';
use POSIX;
use configured_mail;
use PSESSION;
use 5.010;
use Time::Piece;
use URI::Escape; 
 use MIME::Base64;


my $userobj = User -> new();
my $BASEPATH = $userobj ->getAppBasePath();
my $URLBASEPATH = $userobj->getAppBaseUrl();
# my $admin_obj = ADMIN->new($proj,$username);
#my $proj;
#my $username;

my $query = CGI->new(); 
my $CGISESSID = $query->param('CGISESSID');

my $ps = PSESSION->new();
my $ps_outref = $ps->getSessionData("$CGISESSID");
my $proj = $ps_outref->{'proj'};

my ($pdffile,$htmlfile,$curtime);
our $PageNo;

sub generate_pdf
{
                my $file = shift @_;
                my $pdf_path = shift @_;

                my $curtime= localtime(time);
                $curtime =~ s/ /_/g;
                $curtime =~ s/:/_/g;    
                my $time=$curtime;
                $curtime=$pdf_path;

                $htmlfile ="$BASEPATH/macro/$proj/PDF_Report/".$curtime.".html";
                $pdffile="$BASEPATH/macro/$proj/PDF_Report/".$curtime.".pdf";
                open(INFO, ">$htmlfile");
                print INFO $file;
                close(INFO);


                system "../bin/wkhtmltopdf-amd64 -B 15 -L 15 -R 15 --zoom 1.00 --margin-top 10 --footer-spacing 3 --footer-left 'Page:[page]' --footer-right 'Date:$time' --header-center 'BenchMark Report' --footer-center 'Tata Technologies Ltd.' --footer-font-size 12 --header-font-size 15 -O landscape $htmlfile $pdffile";


              return 1;


}
1; 

1 个答案:

答案 0 :(得分:0)

一种解决方案是创建一页的pdf文件集合,每页一个,然后将它们加入到最终的PDF中。

 if (@pdfFilenames > 1){
    my $filenameString = join(' ',@pdfFilenames);
    `pdfunite   $filenameString   joinedFinalAllCombinedPDFfilename.pdf `;
    `rm $filenameString `;
        :
        :
  }

使用pdfunite命令行应用程序。将有其他方法来组合PDF,例如非常有用的pdftk(不是Tk应用程序,AFAIK)

pdftk A=a-doc.pdf B=bbbbb.pdf C=file3.pdf D=page4.pdf\
        cat     C D A1-10 B18 B2 A400-4-2  \
        output  combined.pdf