Post without Account — your post will be reviewed, and if appropriate, posted under Anonymous.

RT 120450 - ->open followed by ->saveas fails

  • 4 Replies
  • 1076 Views
*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 356
    • View Profile
RT 120450 - ->open followed by ->saveas fails
« February 28, 2017, 09:39:44 AM »
Tue Feb 28 01:16:57 2017 The RT System itself - Status changed from 'new' to 'open' Tue Feb 28 01:15:44 2017 $_ = 'spro^^*%*^6ut# [...] &$%*c>#!^!#&!pan.org'; y/a-z.@//cd; print - Ticket created

Version 2.031.

$ perl  -MPDF::API2 -e 'PDF::API2->open("t/4pages.pdf")->saveas("pa.pdf")'
Can't use an undefined value as an ARRAY reference at /Library/Perl/5.12/PDF/API2/Basic/PDF/File.pm line 1276.

I was just trying to rewrite a file that another PDF module couldn’t read (to see if that would make it readable by the other module).  The documentation implies that this should work.

I encountered this problem with PDFs generated by Mac OS X 10.8.5 Quartz PDFContext and those generated by ABBYY FineReader.  (I.e., it does not seem specific to any particular PDF generator.)
#
Tue Feb 28 01:16:56 2017 $_ = 'spro^^*%*^6ut# [...] &$%*c>#!^!#&!pan.org'; y/a-z.@//cd; print - Correspondence added

Sorry, I forgot the subject, but I don’t have permission to set it.  It should be:

->open followed by ->saveas fails
#
Tue Feb 28 01:16:57 2017 The RT System itself - Status changed from 'new' to 'open'

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 356
    • View Profile
Re: RT 120450 - ->open followed by ->saveas fails
« Reply #1: May 24, 2017, 05:47:25 PM »
Tue May 23 22:19:37 2017 steve [...] deefs.net - Correspondence added

This is a known issue with cross-reference streams, which are currently read-only in PDF::API2 (dup. of RT #117184).

======================================================
Just to clarify, 120450 is NOT a dupe of 117184, and does NOT involve cross-reference streams.
It is a separate issue, and has its own patch below.
======================================================


#
Tue May 23 22:19:37 2017 steve [...] deefs.net - Status changed from 'open' to 'rejected'
« Last Edit: December 25, 2017, 07:57:45 PM by Phil »

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 356
    • View Profile
Re: RT 120450 - ->open followed by ->saveas fails
« Reply #2: May 25, 2017, 09:53:41 AM »
Wed May 24 17:55:38 2017 $_ = 'spro^^*%*^6ut# [...] &$%*c>#!^!#&!pan.org'; y/a-z.@//cd; print - Correspondence added

On Tue May 23 22:19:37 2017, SSIMMS wrote:
Quote
This is a known issue with cross-reference streams, which are currently read-only in PDF::API2 (dup. of RT #117184).

The PDF I tested with is a 1.3 file, here attached.

It seems to be the combination of ‘open’ followed immediately by ‘saveas’ that does not work.  If it is not designed to work that way, would you consider improving the documentation?
Subject:    4pages.pdf

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 356
    • View Profile
Re: RT 120450 - ->open followed by ->saveas fails
« Reply #3: June 26, 2017, 06:40:26 PM »
Wed Jun 21 19:37:23 2017 $_ = 'spro^^*%*^6ut# [...] &$%*c>#!^!#&!pan.org'; y/a-z.@//cd; print - Correspondence added
Subject:    [PATCH] for ->saveas not working
RT-Send-CC:    steve [...] deefs.net

This patch seems to solve the problem.
Subject:    open_QMs6IgBI.txt
Code: [Select]
--- a/lib/PDF/API2/Basic/PDF/File.pm 2017-01-26 10:30:03.000000000 -0800
+++ b/lib/PDF/API2/Basic/PDF/File.pm 2017-06-21 16:33:17.000000000 -0700
@@ -1273,7 +1273,7 @@
     my $tloc = $fh->tell();
     $fh->print("xref\n");
 
-    my @xreflist = sort { $self->{' objects'}{$a->uid}[0] <=> $self->{' objects'}{$b->uid}[0] } (@{$self->{' printed'}}, @{$self->{' free'}});
+    my @xreflist = sort { $self->{' objects'}{$a->uid}[0] <=> $self->{' objects'}{$b->uid}[0] } (@{$self->{' printed'}||[]}, @{$self->{' free'}||[]});
 
     my ($i, $j, $k);
     unless ($update) {
@@ -1294,7 +1294,7 @@
         }
     }
 
-    my @freelist = sort { $self->{' objects'}{$a->uid}[0] <=> $self->{' objects'}{$b->uid}[0] } @{$self->{' free'}};
+    my @freelist = sort { $self->{' objects'}{$a->uid}[0] <=> $self->{' objects'}{$b->uid}[0] } @{$self->{' free'}||[]};
 
     $j = 0; my $first = -1; $k = 0;
     for ($i = 0; $i <= $#xreflist + 1; $i++) {
#
Sat Jun 24 12:48:56 2017 steve [...] deefs.net - Correspondence added

Aha, you're right.  Thanks for the patch.  I've implemented it and added a test case.

On Wed Jun 21 19:37:23 2017, SPROUT wrote:
Show quoted text
#
Sat Jun 24 12:49:02 2017 steve [...] deefs.net - Status changed from 'rejected' to 'patched'

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 356
    • View Profile
Re: RT 120450 - ->open followed by ->saveas fails
« Reply #4: July 03, 2017, 10:40:03 AM »
Sun Jul 02 23:46:51 2017 steve [...] deefs.net - Status changed from 'patched' to 'resolved'
#
Sun Jul 02 23:46:51 2017 steve [...] deefs.net - Fixed in 2.032 added