Post without Account — your post will be reviewed, and if appropriate, posted under Anonymous. You can also use this link to report any problems registering or logging in.

RT 114977 - Losing internal links while splitting document

  • 3 Replies
  • 2589 Views
*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 706
    • View Profile
Wed Jun 01 19:23:02 2016 dosio [...] land.it - Ticket created
Subject:    Losing internal links while splitting document
Date:    Thu, 2 Jun 2016 01:22:46 +0200
To:    bug-PDF-API2 [...] rt.cpan.org
From:    Claudio Dosio <dosio [...] land.it>
 
When I try to split into single pages some PDFs containing one of links, the links get lost in the split document. I have tried to use both the importpage() and the importPageIntoForm() with the same problem.

I have tried the code snippet found in http://www.perlmonks.org/?node_id=982337

but in my case it doesn't work. I saw that this is a problem for many people but could not find any solution to the problem so far.

I have tried on Linux Ubuntu 10.04, 12.04, 14.04 and the most recent 16.04.

Could you please help me?

Best regards,
Claudio

--
Claudio Dosio
Responsabile R&S Software

*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 706
    • View Profile
Re: RT 114977 - Losing internal links while splitting document
« Reply #1: March 22, 2019, 12:09:47 PM »
Update to RT 114977:

The code snippet given was for merging pages into one PDF, so I don't know how applicable it is to your reported problem. Could you please give us a sample PDF (or refer to a public one) and the PDF::API2 code you use to split it, and shows the reported problem? Please also try it with PDF::Builder, in case code changes in that library have fixed the problem.

*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 706
    • View Profile
Re: RT 114977 - Losing internal links while splitting document
« Reply #2: January 14, 2020, 08:50:20 AM »
Mon Jan 13 14:43:39 2020 jv [...] cpan.org - Correspondence added
Code: [Select]
# If the original PDF contains links, they are lost in the copy.

use PDF::API2;

my $output_file = "copy.pdf";
my $output_pdf = PDF::API2->new(-file => $output_file);

foreach my $input_file ("original.pdf") {
    my $input_pdf = PDF::API2->open($input_file);
    my @numpages = (1..$input_pdf->pages());
    foreach my $numpage (@numpages) {
        # add page number $numpage from $input_file to the end of
        # the file $output_file
        $output_pdf->importpage($input_pdf,$numpage,0);       
    }
}

$output_pdf->save();

Same with PDF::Builder.

*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 706
    • View Profile
Re: RT 114977 - Losing internal links while splitting document
« Reply #3: January 17, 2020, 08:48:21 AM »
Tue Jan 14 21:50:39 2020 PMPERRY [...] cpan.org - Correspondence added

What should the expected behavior be? After all, if you have an internal link that goes to a page that does not exist in the new document, presumably it should disappear. If pages are copied over one at a time, this would result in the loss of all off-page links. Maybe all links could be held in some cache, and at the end of the process, either destroyed (if out of document) or preserved. How about modifying a link to point to a new document, assuming all the pages survived some place or another? That could be quite a bit of manual work, unless you do the split and creation of multiple descendant documents all in one operation. This might be a new "partition" operation?