PDF :: FromHTML创建空的PDF [英] PDF::FromHTML creates empty PDF

查看:101
本文介绍了PDF :: FromHTML创建空的PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Perl s PDF::FromHTML创建PDF文件.我的代码如下:

I'm using Perls PDF::FromHTML to create a PDF-file. My code looks like this:

open HTML, ">", "file.html";
...
close HTML;
chmod(0777, "file.html");

my $pdf = PDF::FromHTML->new(encoding => 'utf-8');
$pdf->load_file("file.html") or die $!;

$pdf->convert(
        Font => 'Arial',
        LineHeight => 10,
        Landscape => 1
);

$pdf->write_file("file.pdf") or die $!;

由于一开始我在创建实际的PDF文件时遇到了困难,所以我现在正严格遵循cpan的简介,

Since I had difficulties creating an actual PDF-file at the beginning, I'm now exactly following the synopsis on cpan, which is

my $pdf = PDF::FromHTML->new( encoding => 'utf-8' );

# Loading from a file:
$pdf->load_file('source.html');

# Perform the actual conversion:
$pdf->convert(
    # With PDF::API2, font names such as 'traditional' also works
    Font        => 'font.ttf',
    LineHeight  => 10,
    Landscape   => 1,
);
# Write to a file:
$pdf->write_file('target.pdf');

但是,这会在正确的位置创建一个PDF文件,但是它仅包含一个白页. HTML文件已完成,看起来应该看起来像.我想念什么?

However this creates a PDF-file at the right location, but it only consists of a white page. The HTML-file is complete and looks like it should look. What am I missing?

推荐答案

您需要指定有效的字体.第二个示例的字体名称无效.

You need to specify a valid font. The second example has a non valid fontname.

如果您安装了PDF :: API2,则可以尝试使用"Helvetica"作为字体名称.

If you installed PDF::API2 you could try to use: 'Helvetica' as fontname.

请检查您的HTML文件,它应该非常简单(没有CSS或javascript).

Please check you HTML file, it should be quite simple (no CSS or javascript).

此致

这篇关于PDF :: FromHTML创建空的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆