Skip Menu |
 

This queue is for tickets about the PDF-API2 CPAN distribution.

Report information
The Basics
Id: 104133
Status: resolved
Priority: 0/
Queue: PDF-API2

People
Owner: Nobody in particular
Requestors: don.huettl [...] grantstreet.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 2.023
Fixed in: 2.024



Subject: bounding box improvements
Download (untitled) / with headers
text/plain 882b
Fixes how the various bounding box objects are handled when copying a page to a new document. I had a PDF with crop marks that were hidden in the original document, but were displayed in the copy. This was due to the fact that we only copied the object used to set the new page's dimensions, which would always be the MediaBox if the PDF is written to spec. In my case, the CropBox should override the MediaBox to hide all the crop marks. The fix is to make sure all bounding box objects get copied to the new page. In addition, the order being used to determine the correct value for any unspecified box objects has been updated to better match the spec. The BleedBox, TrimBox, and ArtBox will all default to the value of the CropBox. The CropBox defaults to MediaBox. If this is applied, please credit my employer, Grant Street Group <gsg@cpan.org>, in addition to myself.
Subject: PDF-API2-2.023-Boxes.patch
commit fd595694e773 Author: Don Huettl <don.huettl@grantstreet.com> Date: Thu Mar 19 15:32:33 2015 -0400 handle boundary boxes correctly when copying pages This reverts the fix added in v2.023.1 and takes a better approach. The BBox object for the frame we are using to embed the new page takes its dimensions in the same manner as before, but the new page will have all its boundary box objects persisted to the new copy. Previously, only the MediaBox object was being copied. In addition, updates the order being used to determine the correct value for any unspecified box objects to better match the spec. The BleedBox, TrimBox, and ArtBox will all default to the value of the CropBox. The CropBox defaults to the MediaBox. diff --git a/PDF-API2/lib/PDF/API2.pm b/PDF-API2/lib/PDF/API2.pm index 7c7182eacbc6..f93e0c8404bb 100644 --- a/PDF-API2/lib/PDF/API2.pm +++ b/PDF-API2/lib/PDF/API2.pm @@ -1288,12 +1288,13 @@ sub importPageIntoForm { $self->{apiimportcache}||={}; $self->{apiimportcache}->{$s_pdf}||={}; + # Should never get past MediaBox, since it is a required object. foreach my $k (qw( MediaBox ArtBox TrimBox BleedBox CropBox )) { #next unless(defined $s_page->{$k}); #my $box = walk_obj($self->{apiimportcache}->{$s_pdf},$s_pdf->{pdf},$self->{pdf},$s_page->{$k}); next unless(defined $s_page->find_prop($k)); my $box = walk_obj($self->{apiimportcache}->{$s_pdf},$s_pdf->{pdf},$self->{pdf},$s_page->find_prop($k)); $xo->bbox(map { $_->val } $box->elementsof); } $xo->bbox( 0, 0, 612, 792) unless(defined $xo->{BBox}); @@ -1406,7 +1407,18 @@ sub import_page { # all that nasty resources from polluting # our very own resource naming space. my $xo = $self->importPageIntoForm($s_pdf,$s_page); - $t_page->mediabox( map { $_->val } $xo->{BBox}->elementsof) if(defined $xo->{BBox}); + + # copy all page dimensions + foreach my $k (qw( MediaBox ArtBox TrimBox BleedBox CropBox )) { + my $prop = $s_page->find_prop($k); + next unless defined $prop; + + my $box = walk_obj({}, $s_pdf->{pdf}, $self->{pdf}, $prop); + my $method = lc($k); + + $t_page->$method(map { $_->val } $box->elementsof); + } + $t_page->gfx->formimage($xo,0,0,1); # copy annotations and/or form elements as well diff --git a/PDF-API2/lib/PDF/API2/Page.pm b/PDF-API2/lib/PDF/API2/Page.pm index 20552d5a2975..185b0e2170c6 100644 --- a/PDF-API2/lib/PDF/API2/Page.pm +++ b/PDF-API2/lib/PDF/API2/Page.pm @@ -144,7 +144,7 @@ Gets the cropbox based one best estimates or the default. sub get_cropbox { my $self = shift(); - return _get_bbox($self, [qw(CropBox BleedBox TrimBox ArtBox MediaBox)]); + return _get_bbox($self, [qw(CropBox MediaBox BleedBox TrimBox ArtBox)]); } =item $page->bleedbox $w, $h @@ -169,7 +169,7 @@ Gets the bleedbox based one best estimates or the default. sub get_bleedbox { my $self = shift(); - return _get_bbox($self, [qw(BleedBox TrimBox ArtBox MediaBox CropBox)]); + return _get_bbox($self, [qw(BleedBox CropBox MediaBox TrimBox ArtBox)]); } =item $page->trimbox $w, $h @@ -192,7 +192,7 @@ Gets the trimbox based one best estimates or the default. sub get_trimbox { my $self = shift(); - return _get_bbox($self, [qw(TrimBox ArtBox MediaBox CropBox BleedBox)]); + return _get_bbox($self, [qw(TrimBox CropBox MediaBox ArtBox BleedBox)]); } =item $page->artbox $w, $h @@ -217,7 +217,7 @@ Gets the artbox based one best estimates or the default. sub get_artbox { my $self = shift(); - return _get_bbox($self, [qw(ArtBox TrimBox BleedBox CropBox MediaBox)]); + return _get_bbox($self, [qw(ArtBox CropBox MediaBox TrimBox BleedBox)]); } =item $page->rotate $deg
Download (untitled) / with headers
text/plain 275b
This looks good. While it's introducing a change of behavior to copy the other bounding boxes when importing a page, I think it's appropriate to do so. If you're reading this post-release and think otherwise, please include details as to why you think it shouldn't be done.
Patched on BitBucket, and will be included in the next release. Thanks!


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.