如何使用PDF :: API2 Perl模块设置字体颜色?

4 pdf perl fonts

我需要使用PDF :: API2为PDF文档中的某些文本添加颜色 - 我该怎么做?

Ste*_*mms 5

您可以fillcolor在添加文本之前通过调用方法来设置文本颜色:

use PDF::API2;

my $pdf = PDF::API2->new();              # Create a PDF
my $font = $pdf->corefont('Helvetica');  # Add a font to the PDF
my $page = $pdf->page();                 # Create a page to hold your text
my $text = $page->text();                # Create a graphics/text object

$text->font($font, 12);                  # Set the font and size for your text
$text->fillcolor('#FF0000');             # Set the text color
$text->text('This text will be red.');   # Add your text
Run Code Online (Sandbox Code Playgroud)

在大多数情况下,Web样式的颜色名称可能会正常工作,但您可以使用"%"而不是"#"来传递CMYK颜色并传递四个值(例如,%00FF0000对于品红色).

PDF :: API2 ::内容的文件有会影响各种方法的详细信息$text的对象.