On Thu, 5 Jul 2007 21:45:03 +0200, Michael Schierl wrote:
> Anyway, my current patch is attached.
forgot to attach some sample code (will convert multiple pdfs to one pdf
with 4 pages per page):
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class HyperlinksSurvive {
public static void main(String[] args) throws IOException,
DocumentException {
preserveLinkSample(new String[] {"withlinks.pdf",
"Diplomarbeit_Michael_Schierl.pdf",
"hyperref.pdf"}, "output.pdf");
}
public static void preserveLinkSample(String[] files, String outputFile)
throws IOException, DocumentException {
int firstPage=1;
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(outputFile));
document.setPageSize(PageSize.A4);
float W = PageSize.A4.getWidth() / 2;
float H = PageSize.A4.getHeight() / 2;
document.open();
PdfContentByte cb = writer.getDirectContent();
for (int i = 0; i < files.length; i++) {
PdfReader currentReader = new PdfReader(files[i]);
currentReader.consolidateNamedDestinations();
for (int page = 1; page <=
currentReader.getNumberOfPages(); page++) {
PdfImportedPage importedPage =
writer.getImportedPage(
currentReader, page);
float a = 0.5f;
float e = (page % 2 == 0) ? W : 0;
float f = (page % 4 == 1 || page % 4 == 2) ? H
: 0;
PdfAnnotation.PdfImportedLink[] links =
currentReader.getLinks(page);
cb.addTemplate(importedPage, a, 0, 0, a, e, f);
for (int j = 0; j < links.length; j++) {
if (links[j].isInternal()) {
int dPage =
links[j].getDestinationPage();
int newDestPage = (dPage-1)/4 +
firstPage;
float ee = (dPage % 2 == 0) ? W
: 0;
float ff = (dPage % 4 == 1 ||
dPage % 4 == 2) ? H : 0;
links[j].setDestinationPage(newDestPage);
links[j].transformDestination(a, 0, 0, a, ee, ff);
}
links[j].transformRect(a, 0, 0, a, e,
f);
writer.addAnnotation(links[j].createAnnotation(writer));
}
if (page % 4 == 0)
document.newPage();
}
if (i < files.length - 1)
document.newPage();
firstPage += (currentReader.getNumberOfPages()+3)/4;
}
document.close();
}
}
--
#!/usr/bin/perl -I' # tekscribble.pl - start in an xterm and scribble with mouse
$|=1;$g="\35";sub g{getc}sub [EMAIL PROTECTED]"stty
-icanon";p"\233?38h";for(;;){
p"$g\33\32";$_=g;$x=g;$X=g;$y=g;$Y=g;last if/q/;$k=$y.chr((ord$Y)+64).$x.chr((
ord$X)+32);p"\33\14"if/c/;p$g.(/ì/?$l:$k).$k;$l=$k;}p"\33\3";system"stty icanon"
-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/