use C4::Debug;
use C4::Context;
use autouse 'C4::Members' => qw(GetPatronImage GetMember);
-use C4::Creators::PDF 1.000000;
-use C4::Patroncards::Batch 1.000000;
-use C4::Patroncards::Template 1.000000;
-use C4::Patroncards::Layout 1.000000;
-use C4::Patroncards::Patroncard 1.000000;
+use C4::Creators 1.000000;
+use C4::Patroncards 1.000000;
my $cgi = new CGI;
my $upper_right_x = $template->get_attr('page_width');
my $upper_right_y = $template->get_attr('page_height');
-$pdf->Compress(1);
+$pdf->Compress(1); # comment this out to debug pdf files, but be sure to uncomment it in production or you may be very sorry...
$pdf->Mbox($lower_left_x, $lower_left_y, $upper_right_x, $upper_right_y);
my ($llx, $lly) = 0,0;
$items = $batch->get_attr('items');
}
-my $layout_xml = XMLin($layout->get_attr('layout_xml'));
+my $layout_xml = XMLin($layout->get_attr('layout_xml'), ForceArray => 1);
if ($layout_xml->{'page_side'} eq 'B') { # rearrange items on backside of page to swap columns
my $even = 1;
my $card_number = GetMember(borrowernumber => $borrower_number)->{'cardnumber'};
# Set barcode data
- $layout_xml->{'barcode'}->{'data'} = $card_number if $layout_xml->{'barcode'};
+ $layout_xml->{'barcode'}->[0]->{'data'} = $card_number if $layout_xml->{'barcode'};
# Create a new patroncard object
my $patron_card = C4::Patroncards::Patroncard->new(
layout => $layout_xml,
text_wrap_cols => 30, #FIXME: hardcoded
);
- $patron_card->draw_guide_box($pdf);
+ $patron_card->draw_guide_box($pdf) if $layout_xml->{'guide_box'};
$patron_card->draw_barcode($pdf) if $layout_xml->{'barcode'};
# Do image foo and place binary image data into layout hash
my $image_data = {};
my $error = undef;
+ my $images = $layout_xml->{'images'};
PROCESS_IMAGES:
- foreach (keys %{$layout_xml->{'images'}}) {
- if (grep{m/source/} keys(%{$layout_xml->{'images'}->{$_}->{'data_source'}})) {
- if ($layout_xml->{'images'}->{$_}->{'data_source'}->{'image_source'} eq 'none') {
+ foreach (keys %{$images}) {
+ if (grep{m/source/} keys(%{$images->{$_}->{'data_source'}->[0]})) {
+ if ($images->{$_}->{'data_source'}->[0]->{'image_source'} eq 'none') {
next PROCESS_IMAGES;
}
- elsif ($layout_xml->{'images'}->{$_}->{'data_source'}->{'image_source'} eq 'patronimages') {
+ elsif ($images->{$_}->{'data_source'}->[0]->{'image_source'} eq 'patronimages') {
($image_data, $error) = GetPatronImage($card_number);
warn sprintf('No image exists for borrower number %s.', $borrower_number) if !$image_data;
next PROCESS_IMAGES if !$image_data;
}
- elsif ($layout_xml->{'images'}->{$_}->{'data_source'}->{'image_source'} eq 'creator_images') {
+ elsif ($images->{$_}->{'data_source'}->[0]->{'image_source'} eq 'creator_images') {
my $dbh = C4::Context->dbh();
$dbh->{LongReadLen} = 1000000; # allows us to read approx 1MB
$image_data = $dbh->selectrow_hashref("SELECT imagefile FROM creator_images WHERE image_name = \'$$layout_xml{'images'}{$_}{'data_source'}{'image_name'}\'");
}
}
else {
- warn sprintf("Unrecognized image data source: %s", $layout_xml->{'images'}->{$_}->{'data_source'});
+ warn sprintf("Unrecognized image data source: %s", $images->{$_}->{'data_source'});
next PROCESS_IMAGES;
}
my $alt_width = ceil($image->Get('width')); # the rounding up is important: Adobe reader does not handle long decimal numbers well
my $alt_height = ceil($image->Get('height'));
my $ratio = $alt_width / $alt_height;
- my $display_height = ceil($layout_xml->{'images'}->{$_}->{'Dx'});
+ my $display_height = ceil($images->{$_}->{'Dx'});
my $display_width = ceil($ratio * $display_height);
$image->Set(magick => 'jpg', quality => 100);
# Write params for alt image...
- $layout_xml->{'images'}->{$_}->{'alt'}->{'Sx'} = $alt_width;
- $layout_xml->{'images'}->{$_}->{'alt'}->{'Sy'} = $alt_height;
- $layout_xml->{'images'}->{$_}->{'alt'}->{'data'} = $alt_image->ImageToBlob();
+ $images->{$_}->{'alt'}->{'Sx'} = $alt_width;
+ $images->{$_}->{'alt'}->{'Sy'} = $alt_height;
+ $images->{$_}->{'alt'}->{'data'} = $alt_image->ImageToBlob();
# Write params for display image...
- $layout_xml->{'images'}->{$_}->{'Sx'} = $display_width;
- $layout_xml->{'images'}->{$_}->{'Sy'} = $display_height;
- $layout_xml->{'images'}->{$_}->{'data'} = $image->ImageToBlob();
+ $images->{$_}->{'Sx'} = $display_width;
+ $images->{$_}->{'Sy'} = $display_height;
+ $images->{$_}->{'data'} = $image->ImageToBlob();
my $err = $patron_card->draw_image($pdf);
warn sprintf ("Error encountered while attempting to draw image %s, %s", $_, $err) if $err;