Larry Schmidlin wrote:

Is there an easy way to create a pdf in the Printer's Spread format using iText? i.e., I'm making a 20 page book and the pages are 2 sided, but half the size of a regular letter size. Thus, 4 pages are put on a piece of paper, 2 pages on each side of the piece of paper. The paper is then cut or folded to create the book. (A very common book size in bookstores).
One printer says he'd prefer to see the pages like
20/1 & 2/19,
18/3 & 4/17,
16/5 & 6/15,
14/7 & 8/13,
12/9 & 10/11
Another printer says to create
1/4 & 2/3,
5/8 & 6/7,
9/12 & 10/11,
13/16 & 14/15,
17/20 & 18/19.

I see how I could play some tricks doing something similar to the TwoOnOne example by creating some temporary pdfs, then combining them, but thought I'd check if someone has solved it already.

For the Manning Book I have made the following example.
It puts a 4 page document on 1 page so that it can be folded.
You'll have to adapt the code, but especially the lines with
addTemplate should be interesting for you.

       Document document = new Document(PageSize.A4);
       try {
           // we create a PdfReader object
           PdfReader reader = new PdfReader("HelloUniverse.pdf");
           // step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("HelloWorldFolded.pdf"));
           // step 3
           document.open();
           // step 4
           PdfContentByte cb = writer.getDirectContent();
           PdfImportedPage page;
           page = writer.getImportedPage(reader, 1);
cb.addTemplate(page, -0.5f, 0f, 0f, -0.5f, PageSize.A4.width() / 2, PageSize.A4.height());
           page = writer.getImportedPage(reader, 2);
           cb.addTemplate(page, 0.5f, 0f, 0f, 0.5f, 0f, 0f);
           page = writer.getImportedPage(reader, 3);
cb.addTemplate(page, 0.5f, 0f, 0f, 0.5f, PageSize.A4.width() / 2f, 0f);
           page = writer.getImportedPage(reader, 4);
cb.addTemplate(page, -0.5f, 0f, 0f, -0.5f, PageSize.A4.width(), PageSize.A4.height());
           cb.setLineDash(20, 10, 10);
           cb.moveTo(0, PageSize.A4.height() / 2f);
           cb.lineTo(PageSize.A4.width(), PageSize.A4.height() / 2f);
           cb.stroke();
           cb.moveTo(PageSize.A4.width() / 2f, 0);
           cb.lineTo(PageSize.A4.width() / 2f, PageSize.A4.height());
           cb.stroke();
       } catch (IOException e) {
           e.printStackTrace();
       } catch (DocumentException e) {
           e.printStackTrace();
       }
       // step 5
       document.close();

br,
Bruno


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very
own Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to