免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3839 | 回复: 5
打印 上一主题 下一主题

perl 处理文件以PDF格式输出 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-17 18:55 |只看该作者 |倒序浏览
10可用积分
各位,
我现在用PERL把HTML写成WORD,但是WORD不是最理想的输出格式(而且操作极其不理想),于是想到了
PDF,但是在网上查了资料,很是有困难,大家有什么高招,请赐教,谢谢。

[ 本帖最后由 chinatzbcn 于 2008-6-17 19:01 编辑 ]

最佳答案

查看完整内容

Using CPAN module PDF::Create1. install PDF::Create2. read perldoc PDF::Create3. Sample code

论坛徽章:
0
2 [报告]
发表于 2008-06-17 18:55 |只看该作者

回复 #1 chinatzbcn 的帖子

Using CPAN module PDF::Create
1. install PDF::Create
2. read perldoc PDF::Create
3. Sample code
use strict;
use PDF::Create;
my $pdf = new PDF::Create(
    'filename' => 'myPerl.pdf',
    'Version'  => 1.2,
    'PageMode' => 'UseOutlines',
    'Author'   => 'ulmer@chinaunix.net',
    'Title'    => 'Perl in ChinaUnix',
);
# set page size
my $root = $pdf->new_page('MediaBox' => [ 0, 0, 612, 792 ]);

# Add a page which inherits its attributes from $root
my $page = $root->new_page;

# Prepare 2 fonts
my $encode = 'WinAnsiEncoding';
my $font = 'Helvetica';
my $font_b = 'Helvetica-Bold';
# fonts obj
my $oF = $pdf->font('Subtype'=>'Type1','Encoding'=>$encode,'BaseFont'=>$font);
my $oFb = $pdf->font('Subtype'=>'Type1','Encoding'=>$encode,'BaseFont'=>$font_b);

# Prepare a Table of Content
my $toc = $pdf->new_outline('Title'=>'Perl', 'Destination'=>$page);
$toc->new_outline('Title' => 'Introduction');
my $s2 = $toc->new_outline('Title' => 'Variables', 'Status' => 'closed');
$s2->new_outline('Title' => 'Scalar');

$page->stringc($oFb, 40, 306, 426, "Perl - Introduction");
$page->stringc($oF, 20, 306, 396, "written by ulmer");

# Add another page
my $page2 = $root->new_page;
$page2->line(0, 0, 612, 792);
$page2->line(0, 792, 612, 0);

$toc->new_outline('Title' => 'Oprater');
$pdf->new_outline('Title' => 'Summary');

# Add something to the first page
$page->stringc($oF, 20, 306, 300, 'Perl makes life easy!');

# Add the missing PDF objects and a the footer then close the file
$pdf->close;

论坛徽章:
0
3 [报告]
发表于 2008-06-17 19:10 |只看该作者
html2pdf 有现成的软件的

论坛徽章:
0
4 [报告]
发表于 2008-06-17 19:46 |只看该作者
去CPAN上找,相关的模块一大把

论坛徽章:
0
5 [报告]
发表于 2008-12-30 16:45 |只看该作者
谢谢各位的回答。。。

论坛徽章:
0
6 [报告]
发表于 2008-12-31 10:49 |只看该作者
感觉PDF::Create写起来好麻烦啊,Html2PDF应该比较方便些吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP