View | Details | Raw Unified | Return to bug 13954
Collapse All | Expand All

(-)a/C4/Patroncards/Patroncard.pm (+1 lines)
Lines 194-199 sub draw_image { Link Here
194
        my $intName = $pdf->AltJpeg($images->{$image}->{'data'},$images->{$image}->{'Sx'}, $images->{$image}->{'Sy'}, 1, $images->{$image}->{'alt'}->{'data'},$images->{$image}->{'alt'}->{'Sx'}, $images->{$image}->{'alt'}->{'Sy'}, 1);
194
        my $intName = $pdf->AltJpeg($images->{$image}->{'data'},$images->{$image}->{'Sx'}, $images->{$image}->{'Sy'}, 1, $images->{$image}->{'alt'}->{'data'},$images->{$image}->{'alt'}->{'Sx'}, $images->{$image}->{'alt'}->{'Sy'}, 1);
195
        my $obj_stream = "q\n";
195
        my $obj_stream = "q\n";
196
        $obj_stream .= "$images->{$image}->{'Sx'} $images->{$image}->{'Ox'} $images->{$image}->{'Oy'} $images->{$image}->{'Sy'} $Tx $Ty cm\n";       # see http://www.adobe.com/devnet/pdf/pdf_reference.html sec 8.3.3 of ISO 32000-1
196
        $obj_stream .= "$images->{$image}->{'Sx'} $images->{$image}->{'Ox'} $images->{$image}->{'Oy'} $images->{$image}->{'Sy'} $Tx $Ty cm\n";       # see http://www.adobe.com/devnet/pdf/pdf_reference.html sec 8.3.3 of ISO 32000-1
197
        $obj_stream .= "$images->{$image}->{'scale'} 0 0 $images->{$image}->{'scale'} 0 0 cm\n"; #scale to 20%
197
        $obj_stream .= "/$intName Do\n";
198
        $obj_stream .= "/$intName Do\n";
198
        $obj_stream .= "Q\n";
199
        $obj_stream .= "Q\n";
199
        $pdf->Add($obj_stream);
200
        $pdf->Add($obj_stream);
(-)a/patroncards/create-pdf.pl (-13 / +20 lines)
Lines 63-69 print $cgi->header( -type => 'application/pdf', Link Here
63
63
64
my $pdf = C4::Creators::PDF->new(InitVars => 0);
64
my $pdf = C4::Creators::PDF->new(InitVars => 0);
65
my $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
65
my $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
66
my $template = C4::Patroncards::Template->retrieve(template_id => $template_id, profile_id => 1);
66
my $pc_template = C4::Patroncards::Template->retrieve(template_id => $template_id, profile_id => 1);
67
my $layout = C4::Patroncards::Layout->retrieve(layout_id => $layout_id);
67
my $layout = C4::Patroncards::Layout->retrieve(layout_id => $layout_id);
68
68
69
$| = 1;
69
$| = 1;
Lines 71-84 $| = 1; Link Here
71
# set the paper size
71
# set the paper size
72
my $lower_left_x  = 0;
72
my $lower_left_x  = 0;
73
my $lower_left_y  = 0;
73
my $lower_left_y  = 0;
74
my $upper_right_x = $template->get_attr('page_width');
74
my $upper_right_x = $pc_template->get_attr('page_width');
75
my $upper_right_y = $template->get_attr('page_height');
75
my $upper_right_y = $pc_template->get_attr('page_height');
76
76
77
$pdf->Compress(1); # comment this out to debug pdf files, but be sure to uncomment it in production or you may be very sorry...
77
$pdf->Compress(1); # comment this out to debug pdf files, but be sure to uncomment it in production or you may be very sorry...
78
$pdf->Mbox($lower_left_x, $lower_left_y, $upper_right_x, $upper_right_y);
78
$pdf->Mbox($lower_left_x, $lower_left_y, $upper_right_x, $upper_right_y);
79
79
80
my ($llx, $lly) = 0,0;
80
my ($llx, $lly) = 0,0;
81
(undef, undef, $llx, $lly) = $template->get_label_position($start_label);
81
(undef, undef, $llx, $lly) = $pc_template->get_label_position($start_label);
82
82
83
if (@label_ids) {
83
if (@label_ids) {
84
    my $batch_items = $batch->get_attr('items');
84
    my $batch_items = $batch->get_attr('items');
Lines 126-133 foreach my $item (@{$items}) { Link Here
126
                borrower_number         => $borrower_number,
126
                borrower_number         => $borrower_number,
127
                llx                     => $llx, # lower left corner of the card
127
                llx                     => $llx, # lower left corner of the card
128
                lly                     => $lly,
128
                lly                     => $lly,
129
                height                  => $template->get_attr('label_height'), # of the card
129
                height                  => $pc_template->get_attr('label_height'), # of the card
130
                width                   => $template->get_attr('label_width'),
130
                width                   => $pc_template->get_attr('label_width'),
131
                layout                  => $layout_xml,
131
                layout                  => $layout_xml,
132
                text_wrap_cols          => 30, #FIXME: hardcoded
132
                text_wrap_cols          => 30, #FIXME: hardcoded
133
        );
133
        );
Lines 178-183 foreach my $item (@{$items}) { Link Here
178
        $alt_image->BlobToImage($binary_data);
178
        $alt_image->BlobToImage($binary_data);
179
        $alt_image->Set(magick => 'jpg', quality => 100);
179
        $alt_image->Set(magick => 'jpg', quality => 100);
180
180
181
        #To avoid pixelation have the image 5 times bigger and
182
        #scale it down in PDF itself
183
        my $oversize_factor = 8;
184
        my $pdf_scale_factor = 1 / $oversize_factor;
185
181
        my $alt_width = ceil($image->Get('width')); # the rounding up is important: Adobe reader does not handle long decimal numbers well
186
        my $alt_width = ceil($image->Get('width')); # the rounding up is important: Adobe reader does not handle long decimal numbers well
182
        my $alt_height = ceil($image->Get('height'));
187
        my $alt_height = ceil($image->Get('height'));
183
        my $ratio = $alt_width / $alt_height;
188
        my $ratio = $alt_width / $alt_height;
Lines 185-201 foreach my $item (@{$items}) { Link Here
185
        my $display_width = ceil($ratio * $display_height);
190
        my $display_width = ceil($ratio * $display_height);
186
191
187
192
188
        $image->Resize(width => $display_width, height => $display_height);
193
        $image->Resize(width => $oversize_factor * $display_width, height => $oversize_factor * $display_height);
189
        $image->Set(magick => 'jpg', quality => 100);
194
        $image->Set(magick => 'jpg', quality => 100);
190
195
196
#       Write param for downsizing in pdf
197
            $images->{$_}->{'scale'} = $pdf_scale_factor;
198
191
#       Write params for alt image...
199
#       Write params for alt image...
192
            $images->{$_}->{'alt'}->{'Sx'} = $alt_width;
200
            $images->{$_}->{'alt'}->{'Sx'} = $oversize_factor * $alt_width;
193
            $images->{$_}->{'alt'}->{'Sy'} = $alt_height;
201
            $images->{$_}->{'alt'}->{'Sy'} = $oversize_factor * $alt_height;
194
            $images->{$_}->{'alt'}->{'data'} = $alt_image->ImageToBlob();
202
            $images->{$_}->{'alt'}->{'data'} = $alt_image->ImageToBlob();
195
203
196
#       Write params for display image...
204
#       Write params for display image...
197
            $images->{$_}->{'Sx'} = $display_width;
205
            $images->{$_}->{'Sx'} = $oversize_factor * $display_width;
198
            $images->{$_}->{'Sy'} = $display_height;
206
            $images->{$_}->{'Sy'} = $oversize_factor * $display_height;
199
            $images->{$_}->{'data'} = $image->ImageToBlob();
207
            $images->{$_}->{'data'} = $image->ImageToBlob();
200
208
201
            my $err = $patron_card->draw_image($pdf);
209
            my $err = $patron_card->draw_image($pdf);
Lines 203-209 foreach my $item (@{$items}) { Link Here
203
        }
211
        }
204
        $patron_card->draw_text($pdf);
212
        $patron_card->draw_text($pdf);
205
    }
213
    }
206
    ($llx, $lly, $new_page) = $template->get_next_label_pos();
214
    ($llx, $lly, $new_page) = $pc_template->get_next_label_pos();
207
    $pdf->Page() if $new_page;
215
    $pdf->Page() if $new_page;
208
}
216
}
209
217
210
- 

Return to bug 13954