#!/usr/bin/perl
# $Id: personalize.pl,v 1.7.2.1 2002/01/28 17:17:16 rp Exp $
#
# PDFlib/PDI client: personalization demo
#

use pdflib_pl 4.0;

$col1 = 70;
$col2 = 335;
$infile = "../../doc/PDFlib-purchase-order.pdf";

$p = PDF_new();

if (PDF_open_file($p, "personalize.pdf") == -1) {
    printf(STDERR "Error: cannot open PDF file personalize.pdf.\n");
    exit(2);
}

PDF_set_info($p, "Creator", "personalize.pl");
PDF_set_info($p, "Author", "Thomas Merz");
PDF_set_info($p, "Title", "PDFlib personalization demo (Perl)");

$form = PDF_open_pdi($p, $infile, "", 0);
if ($form == -1) {
    printf(STDERR "Couldn't open input file '%s'.\n", $infile);
    exit(2);
}

$page = PDF_open_pdi_page($p, $form, 1, "");
if ($page == -1) {
    printf(STDERR "Couldn't open page 1 in '%s'.\n", $infile);
    exit(2);
}

$font = PDF_findfont($p, "Helvetica-Bold", "host", 0);

# get the dimensions of the imported form
$width = PDF_get_pdi_value($p, "width", $form, $page, 0);
$height = PDF_get_pdi_value($p, "height", $form, $page, 0);

PDF_begin_page($p, $width, $height);
PDF_place_pdi_page($p, $page, 0, 0, 1, 1);
PDF_close_pdi_page($p, $page);

PDF_setfont($p, $font, 18);
PDF_set_value($p, "leading", 24);
PDF_set_text_pos($p, $col1, 486);

PDF_show($p, "Doublecheck, Inc.");
PDF_continue_text($p, "Petra Porst");
PDF_continue_text($p, "500, Market St.");
PDF_continue_text($p, "94110 San Francisco, CA");
PDF_continue_text($p, "");
PDF_continue_text($p, "USA");
PDF_continue_text($p, "+1/950/123-4567");
PDF_continue_text($p, "+1/950/123-4568");
PDF_continue_text($p, "");
PDF_continue_text($p, "petra\@doublecheck.com");

($tm_sec,$tm_min,$tm_hour,$tm_mday,$tm_mon,$tm_year) = localtime(time);
PDF_set_text_pos($p, $col2, 104);
PDF_continue_text($p, sprintf("%s %d, %d",
	("January", "February", "March", "April", "May", "June",
	"July", "August", "September", "October", "November", "December")
			[$tm_mon], $tm_mday, 1900 + $tm_year));

PDF_end_page($p);
PDF_close($p);
PDF_close_pdi($p, $form);
PDF_delete($p);
