Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » iText »

[iText-questions] How to preserve hyperlinks in PdfImportedPage?

Michael Schierl

2007-06-23

Replies:

Hello,

when I try to resize PDF pages to put more than one of them onto a page,
all hyperlinks on the original pages get lost.

Any ideas how I could preserve them?

Example code (resizes just first page):

------
package jpdftweak;

import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class HyperlinkKiller {
 public static void main(String[] args) throws IOException,
     DocumentException {
   PdfReader currentReader =
     new PdfReader("withlinks.pdf");
   Document document = new Document();
   PdfWriter writer = PdfWriter.getInstance(document,
       new FileOutputStream("scaled.pdf"));
   Rectangle currentSize =
     currentReader.getPageSizeWithRotation(1);
   document.setPageSize(currentSize);
   document.open();
   PdfContentByte cb = writer.getDirectContent();
   PdfImportedPage page =
     writer.getImportedPage(currentReader, 1);
   cb.addTemplate(page, 0.5f, 0, 0, 0.5f,
       0, currentSize.getHeight() / 2);
   document.close();
 }
}
------

Example pdf: http://home.arcor.de/mschierlm/test/withlinks.pdf

Michael

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/
©2008 junlu.com - Jax Systems, LLC, U.S.A.