http://www.perlmonks.org?node_id=1026138

akwe-xavante has asked for the wisdom of the Perl Monks concerning the following question:

Hoping someone can help me with a, what I hope is silly question with a simple answer. I've googled for a couple of hours now and I just don't get it and i'm failing to find an answer

All i'm wanting to do is set the background color of the entire page to a specific hex color. I don't want white I would like to set the page color to #FAF8CC to start with, might turn it down a little further

Here is the first few lines of code

my $pdf = PDF::API2->new(-file => "$SavedAttachment"); $pdf->mediabox(595,842); my $page = $pdf->page; my $fnt = $pdf->corefont('Arial',-encode => 'latin1'); my $txt = $page->text; $txt->textstart; ###### Logo at top center of page # my $image_02 = $page->gfx; my $image_file = $pdf->image_gif("$Logo"); $image_02->image( $image_file, 260,745,72,72 ); ###### Add Customer Name and Address # $txt->font($fnt, 8); $txt->translate(25,630); $txt->fillcolor('black'); $txt->text("$FullCustName");

Replies are listed 'Best First'.
Re: setting PDF background color
by Khen1950fx (Canon) on Mar 30, 2013 at 11:56 UTC
    Run ths first:
    #!/usr/bin/perl use strict; use warnings; use PDF::API2; my $file = 'SavedAttachment.pdf'; my $pdf = PDF::API2->new( -file => $file ); $pdf->mediabox( 595, 842 ); my $page = $pdf->page; my $fnt = $pdf->corefont( 'Arial', -encode => 'latin1' ); my $txt = $page->text; $txt->textstart; $txt->font( $fnt, 8 ); $txt->translate( 25, 630 ); $txt->fillcolor('black'); $txt->text("FullCustName"); $pdf->saveas; exit;
    Then try setpdfbackground.pl from the command line:
    setpdfbackground.pl -o SavedAttachment.pdf 1 fcd SavedAttachment.pdf
    I used fcd because I wanted something neutral and down-to-earth.