On Thu, 16 Apr 2009 20:32:35 +0200, 1T3XT info wrote:

> Michael Schierl wrote:
>> The same exception is thrown if I include the PdfContentByte of that page
>> and copy it over to the new document.
> 
> What do you mean by this? A PdfImportedPage or just a content stream?

// after document.newPage();
PdfContentByte cb = writer.getDirectContent();
cb.addTemplate(writer.getImportedPage(currentReader, 1), 0, 0);
 
>> I removed that part from the example
>> to make it clear that the hyperlinks are the culprit.
> 
> Can you confirm that the hyperlink problem also existed in older versions?

Yes, it also existed in 2.1.2a version.

>>> Unless Michael can explain what he expects to happen.
>> 
>> The hyperlink that happens to be the first one of the hyperlinks on the
>> first page of the source PDF should be "copied" onto the first page of the
>> new PDF (i. e. clicking the same position should result in browsing to the
>> same location).
> 
> The first link on the first page of pagefour.pdf refers to the
> page with reference 27 0 R; in other words to object 27 which is
> the page dictionary of page 3.
> When you copy this link to a new document, there is no page 3 yet.
> You can't use "27 0 R" because you don't even know if object 27 exists
> (or if it contains a page dictionary).

Okay. The original document does not have a page 3 either. So, if I
understand you correctly, the problem is that there is am internal
hyperlink which refers to a nonexisting page? 

The problem seems to be that the isInternal() method of that link returns
false, so I assumed it must be an external hyperlink. (if the
link.isInternal() method returns true, the original code of jPDF Tweak
performs checks whether the destination page number - i. e.
link.getDestinationPage() - is still inside the document to prevent these
kind of problems. I removed them from the testcase to make it a bit more
clear, since I thought the offending link was an external one. Sorry for
the confusion.

>> The same exception appears if I use a loop to move all the hyperlinks. And
>> it still appears if I transform/scale the rectangles of hyperlinks.
> 
> All this seems irrelevant to me.
> The links don't point to a valid page anymore when you "copy" them.

Then it would be cool if there would be a way for me to distinguish these
"internal" links that do not point to anything from really external links.
At the moment, isInternal() is false for both types. If I could distinguish
them, I could just drop those broken links as I do with links that point
outside the range.

> Because using the combination PdfReader/PdfWriter is not the way to go?
> Why don't you use PdfReader/PdfStamper?

I did not know I can move around (scale, rotate, change borders, combine
next to each other) pages in a PdfStamper. JPDF Tweak does all of this, for
example if you want to create 2-up printings or booklets.

> BUT BEFORE WE GO ON: can you please confirm that the "new" problem
> also existed in older iText versions?

It did, as far as I have looked.

> Michael Schierl wrote:
> > And, it still crashes, if you use jPDF Tweak and let it rescale the PDF
> > (scaling both the content and the hyperlinks) to, say, A3 format.
> 
> Let me rephrase my question: has this ever worked?
> Because at first sight, I can't see how it would work.

It worked very well for thousands of other PDF files with lots of internal
links (that did not point to pages that did not exist). But not for that
one I received.

> Take a look at the destinations: 33 0 R and 27 0 R refer to page 
> dictionaries in the original file. What do you expect to happen when you 
> copy those links to another document? There's no way anybody can guess 
> to which page you want the copied links to point at.

That's what the getDestinationPage() and setDestinationPage() are for, as
far as I know, but only for links where isInternal() is true.
Unfortunately, for this link, isInternal() was false, so I thought it must
have been some link to http://www.lowagie.com/ or somewhere else.

> I don't think your second problem was "introduced".
> You could copy the links but you can't copy the parts 33 0 R and 27 0 R 
> to a newly created document. It just doesn't make sense.

You are right. If I could just get true for links like this when I call
isInternal(), I would be very happy :-)

Michael


------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to