Hi, There.
I have created a little program to create a booklet pdf of an existing
multipage pdf.
my problem is that the first page in the created booklet pdf has the
original pagesize, it does not get the newWidth width, why is that ?
here is the program.
import com.lowagie.text.pdf.*;
import com.lowagie.text.*;
import java.io.*;
public class Booklet {
public Booklet() {
}
public void doBooklet(String filename) {
try {
PdfReader reader = new PdfReader(filename);
int numberOfPages = reader.getNumberOfPages();
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("C:/JavaProjects/pbms/nod/files/staging/booklet.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
if(numberOfPages%4 == 0) {
int lastPageCounter = numberOfPages;
int i = 1;
while(i-1 < lastPageCounter) {
Rectangle size =
reader.getPageSizeWithRotation(i);
float newHeight = size.height();
float origWidth = size.width();
float newWidth = size.width()*2;
Rectangle newSize = new Rectangle(newWidth,
newHeight);
document.newPage();
document.setPageSize(newSize);
PdfImportedPage firstPage =
writer.getImportedPage(reader, i);
PdfImportedPage lastPage =
writer.getImportedPage(reader,
lastPageCounter);
int rotation = reader.getPageRotation(i);
if(rotation == 180) {
cb.addTemplate(firstPage, -1f, 0, 0,
-1f, origWidth, newHeight);
cb.addTemplate(lastPage, -1f, 0, 0,
-1f, newWidth, newHeight);
} else if (rotation == 90 || rotation == 270) {
System.out.println("error the page is
rotated 90 degrees");
} else {
System.out.println("adding left page:
" + i);
cb.addTemplate(firstPage, 1f, 0, 0,
1f, 0,0);
System.out.println("adding right page:
" + lastPageCounter);
cb.addTemplate(lastPage, 1f, 0, 0, 1f,
newWidth-origWidth,0);
}
i++;
lastPageCounter--;
}
} else {
System.out.println("Cannot create booklet, wrong
number of pages.");
}
document.close();
} catch(Exception e) {
System.out.println("Exceptoion cauth");
e.printStackTrace();
}
}
// Test main
public static void main(String[] args) {
Booklet booklet = new Booklet();
String file = "C:\\A3017081.PDF";
booklet.doBooklet(file);
}
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions