thanks
I translate your code into python as following in a few minutes :)

'''
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 '''
import os, sys
import math

import jpype
sys.path.append(r'E:\prg\py\pure_pylib\_jpype')


p=r"e:/prg/Java/jdk1.6.0_10/jre/bin/client/jvm.dll"
l=os.path.normpath(os.path.join(os.path.split(os.path.realpath(__file__))[0],
'jfreechart-1.0.13/lib'))
jpype.startJVM(p, r'-Djava.ext.dirs=e:\_prg_bak\java\itext' )


from  com.lowagie.text.Document import *
from com.lowagie.text.DocumentException import *
from com.lowagie.text.Rectangle import *
from  com.lowagie.text.pdf.PdfContentByte import *
from  com.lowagie.text.pdf.PdfImportedPage import *
from  com.lowagie.text.pdf.PdfReader import *
from  com.lowagie.text.pdf.PdfWriter import *


#/** Format of the resulting PDF files. */
RESULT  = "result%dup.pdf"

'''**
 * Manipulates a PDF file src with the file dest as result
 * @param src the original PDF
 * @param dest the resulting PDF
 * @param pow the PDF will be N-upped with N = Math.pow(2, pow);
 * @throws IOException
 * @throws DocumentException
 * @throws SQLException
 */
 '''
def manipulatePdf(src, dest, pow):

    # reader for the src file
    print 'src=', src
    reader = PdfReader(src);
    # initializations
    pageSize = reader.getPageSize(1);

    newSize = [
        Rectangle(pageSize.getWidth(), pageSize.getHeight()),
        Rectangle(pageSize.getHeight(), pageSize.getWidth())
        ][(pow % 2) != 0]

    unitSize = Rectangle(pageSize.getWidth(), pageSize.getHeight())
    for i in range(pow):
        unitSize = Rectangle(unitSize.getHeight() / 2, unitSize.getWidth());

    print 'pow=',pow
    n = int(math.pow(2,  pow))
    r = int(math.pow(2, (pow / 2)))
    c = int(n / r)

    print 'n=%d, r=%d, c=%d' %(n, r, c)
    # step 1
    document = Document(newSize, 0, 0, 0, 0);

    # step 2
    writer = PdfWriter.getInstance(document, FileOutputStream(dest % n ))

    # step 3
    document.open();

    # step 4
    cb = writer.getDirectContent();
    total = reader.getNumberOfPages();
    for i in range(total):
        if (i % n == 0) :
            document.newPage();


        currentSize = reader.getPageSize(i+1)


        factor = min(
            unitSize.getWidth() / currentSize.getWidth(),
            unitSize.getHeight() / currentSize.getHeight());
        offsetX = unitSize.getWidth() * ((i % n) % c) \
          + (unitSize.getWidth() - (currentSize.getWidth() * factor)) / 2.0;
        offsetY = newSize.getHeight() - (unitSize.getHeight() * (((i %
n) / c) + 1)) \
          + (unitSize.getHeight() - (currentSize.getHeight() * factor)) / 2.0;
        page = writer.getImportedPage(reader, i+1);
        cb.addTemplate(page, factor, 0, 0, factor, offsetX, offsetY);

    #step 5
    document.close();


'''
 * Main method.
 * @param args no arguments needed
 * @throws DocumentException
 * @throws IOException
 * @throws SQLException
 */'''
def main():
    sys.argv=['','test.pdf']

    if len(sys.argv)==2:
        args=sys.argv[1]
        print args
        print RESULT

        manipulatePdf(args, RESULT, 1);
        manipulatePdf(args, RESULT, 2);
        manipulatePdf(args, RESULT, 3);
        manipulatePdf(args, RESULT, 4);

main()

2010/7/12  <[email protected]>:
> Send iText-questions mailing list submissions to
>        [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        https://lists.sourceforge.net/lists/listinfo/itext-questions
> or, via email, send a message with subject or body 'help' to
>        [email protected]
>
> You can reach the person managing the list at
>        [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of iText-questions digest..."
>
>
> Today's Topics:
>
>   1. Re: Possible bug using ENCRYPTION_AES_128 and
>      DO_NOT_ENCRYPT_METADATA (Paulo Soares)
>   2. Recompressing the iText PDF library jar (Marko Elezovi?)
>   3. how to put multi pages onto one? (oyster)
>   4. Re: Can I have differnt Page sizes in a single    document using
>      Itextsharp? (Shahan Ayyub)
>   5. Re: Can I have differnt Page sizes in a single document using
>      Itextsharp? (1T3XT info)
>   6. Re: how to put multi pages onto one? (1T3XT info)
>   7. Re: iText and text wrapping using (Multi)ColumnText (1T3XT info)
>   8. Re: '>' not expected at file pointer 558 (Andreas Ebbert-Karroum)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sun, 11 Jul 2010 16:43:35 +0100
> From: "Paulo Soares" <[email protected]>
> Subject: Re: [iText-questions] Possible bug using ENCRYPTION_AES_128
>        and     DO_NOT_ENCRYPT_METADATA
> To: "Post all your questions about iText here"
>        <[email protected]>
> Message-ID: <00d001cb2110$0eb09d00$587ba...@psoaresw>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Fixed.
>
> Paulo
>  ----- Original Message -----
>  From: Paulo Soares
>  To: Post all your questions about iText here
>  Sent: Tuesday, July 06, 2010 11:54 AM
>  Subject: Re: [iText-questions] Possible bug using ENCRYPTION_AES_128 and 
> DO_NOT_ENCRYPT_METADATA
>
>
>  I'll look into this.
>
>  Paulo
>
>  ________________________________________
>  From: smilyface [[email protected]]
>  Sent: Tuesday, July 06, 2010 10:13 AM
>  To: [email protected]
>  Subject: Re: [iText-questions] Possible bug using ENCRYPTION_AES_128 and 
> DO_NOT_ENCRYPT_METADATA
>
>  There seems to a problem with the parameter PdfWriter.EMBEDDED_FILES_ONLY
>  too.
>
>  Check out the test file.
>
>  Best regards,
>
>  Frank
>  http://itext-general.2136553.n4.nabble.com/file/n2279255/TestMain.java
>  TestMain.java
> -------------- next part --------------
> An HTML attachment was scrubbed...
>
> ------------------------------
>
> Message: 2
> Date: Sun, 11 Jul 2010 18:46:25 +0200
> From: Marko Elezovi? <[email protected]>
> Subject: [iText-questions] Recompressing the iText PDF library jar
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=UTF-8; format=flowed
>
>
>
> Hello everyone!
>
> I took the liberty of going through the iText-5.0.2.jar contents with
> some pretty intense compression trials and there is some room for
> improvement.
>
> To keep a long story short, this is what I managed to cook up in a few
> hundred CPU hours:
> http://holizip.com/iText/5.0.2/
>
> Basically, I've managed to reduce the size of the distribution jar by
> aprox. 5% while still following the official jar rules - I've only used
> deflate compression method, the first two entries in the jar dictionary
> are META-INF, and META-INF/MANIFEST.MF, there is no directory clobbering
> - basically, the contents of the jar are exactly matching up to the
> original jars (CRC and date-wise, even the same file order inside the
> jars) except that they have been thinned up by a few percent due to
> some intensive crunching using 7zip's trials, and some other free
> compression tools. One could hot-plug this jar into any installation
> which used the original iText-5.0.2.jar.
>
> My train of thought was that it would not just reduce the amount of data
> users have to download but also reduce any package which will embed the
> iText library.
>
> I was hoping to perform the same kind of recompression for all future
> releases of iText, so that I could provide re-compressed jar libraries
> as soon as the next version comes out (I am willing to host these
> optimized versions on my website, under the iText/ section).
>
> I would be very interested in hearing what you think!
>
> With kind regards,
> Marko Elezovi?
>
>
>
>
>
> ------------------------------
>
> Message: 3
> Date: Mon, 12 Jul 2010 10:25:52 +0800
> From: oyster <[email protected]>
> Subject: [iText-questions] how to put multi pages onto one?
> To: [email protected]
> Message-ID:
>        <[email protected]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> just like what we can do with a real printer
>
> for example, I often put every 4 pages from a pdf file onto one A4 page,
>
> 1. the 4 pages is arranged as
> +--------+---------+
> |    1    |     2   |
> +-------+---------+
> |    3   |     4   |
> +------+----------+
>
> 2. every original page is scaled to fit the 1/4 A4 space as possible as it can
>
> 3. then the new pdf is saved
>
> any hints for the functions to be used?
>
> thanks
>
>
>
> ------------------------------
>
> Message: 4
> Date: Mon, 12 Jul 2010 05:26:29 +0000 (UTC)
> From: Shahan Ayyub <[email protected]>
> Subject: Re: [iText-questions] Can I have differnt Page sizes in a
>        single  document using Itextsharp?
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=us-ascii
>
> kaiomarz engineer <kaiomarz.engineer <at> gmail.com> writes:
>
>>
>> How can I add different sized Pages to a PDF using Itextsharp.When im
> creating a document, the Pagesize is set for an entire document in the
> constructor itself.I have to create a report in PDF, whose page sizes will
> change dynamically ,e.g : first page will be a A4, second a Letter,third A4-
> landscape...ThanksKaiomarz
>>
>> -----------------------------------------------------------------------------
> -
>> This SF.net email is sponsored by Sprint
>> What will you do first with EVO, the first 4G phone?
>> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>>
>> _______________________________________________
>> iText-questions mailing list
>> iText-questions <at> lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>
>> Buy the iText book: http://www.itextpdf.com/book/
>> Check the site with examples before you ask questions:
> http://www.1t3xt.info/examples/
>> You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
>
>
> Does it helps you :
>
> http://stackoverflow.com/questions/2019246/itextsharp-table-in-landscape
> Try to vary the size in the argument list where 800 and 600 are mention.
>
>
>
>
> ------------------------------
>
> Message: 5
> Date: Mon, 12 Jul 2010 07:58:23 +0200
> From: 1T3XT info <[email protected]>
> Subject: Re: [iText-questions] Can I have differnt Page sizes in a
>        single document using Itextsharp?
> To: Post all your questions about iText here
>        <[email protected]>
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Shahan Ayyub wrote:
>> kaiomarz engineer <kaiomarz.engineer <at> gmail.com> writes:
>>
>>> How can I add different sized Pages to a PDF using Itextsharp.When im
>> creating a document, the Pagesize is set for an entire document in the
>> constructor itself.I have to create a report in PDF, whose page sizes will
>> change dynamically ,e.g : first page will be a A4, second a Letter,third A4-
>> landscape...
>
> This question was already answered!
> http://article.gmane.org/gmane.comp.java.lib.itext.general/52467
> Please don't double post!
> --
> This answer is provided by 1T3XT BVBA
> http://www.1t3xt.com/ - http://www.1t3xt.info
>
>
>
> ------------------------------
>
> Message: 6
> Date: Mon, 12 Jul 2010 08:01:52 +0200
> From: 1T3XT info <[email protected]>
> Subject: Re: [iText-questions] how to put multi pages onto one?
> To: Post all your questions about iText here
>        <[email protected]>
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> oyster wrote:
>> just like what we can do with a real printer
>>
>> for example, I often put every 4 pages from a pdf file onto one A4 page,
>>
>> 1. the 4 pages is arranged as
>> +--------+---------+
>> |    1    |     2   |
>> +-------+---------+
>> |    3   |     4   |
>> +------+----------+
>
> If you browse the figures in the iText book, you'll find this:
> http://www.flickr.com/photos/itextinaction/4330324278/
>
>> 2. every original page is scaled to fit the 1/4 A4 space as possible as it 
>> can
>>
>> 3. then the new pdf is saved
>>
>> any hints for the functions to be used?
>
> As you can see, the title of the image on Flicks is "6.5"
> and it has the caption "N-up copying: combining multiple pages
> onto one page"
>
> This means you'll find an example on how to do this in chapter 6
> of the book, more specifically in section 6.2.3, entitle "N-up
> copying and tiling PDF documents"
>
> See http://itextpdf.com/book/
> --
> This answer is provided by 1T3XT BVBA
> http://www.1t3xt.com/ - http://www.1t3xt.info
>
>
>
> ------------------------------
>
> Message: 7
> Date: Mon, 12 Jul 2010 08:14:07 +0200
> From: 1T3XT info <[email protected]>
> Subject: Re: [iText-questions] iText and text wrapping using
>        (Multi)ColumnText
> To: Post all your questions about iText here
>        <[email protected]>
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> genti wrote:
>> Hello everyone,
>>
>> I am currently using iText (the .NET ported version) to wrap text inside an
>> invisible box of a certain width and height.
>
> Without reading about the real problem, the standard answer when people
> have trouble using MultiColumnText is: "Switch to using ColumnText."
>
> MultiColumnText is to be used FOR SIMPLE CASES ONLY.
> Don't use it if you want special things.
> --
> This answer is provided by 1T3XT BVBA
> http://www.1t3xt.com/ - http://www.1t3xt.info
>
>
>
> ------------------------------
>
> Message: 8
> Date: Mon, 12 Jul 2010 09:10:40 +0200
> From: Andreas Ebbert-Karroum <[email protected]>
> Subject: Re: [iText-questions] '>' not expected at file pointer 558
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=ISO-8859-15; format=flowed
>
> Hi,
>
> so far I have not received a reply to my question. If I can provide you
> with more detail or background, what do you still need to know? Or has
> the question already been answered somewhere? I'm also willing to patch
> iText myself, when I get a rough hint how and where.
>
> We're currently blocked with our automated acceptance tests, since we
> cannot process the generated PDFs.
>
> Thanks,
> Andreas
>
> Am 08.07.2010 18:18, schrieb Andreas Ebbert-Karroum:
>> Hi,
>>
>> I'd like to discuss the problem again, that was mentioned in those
>> posts on the mailing list:
>>
>> http://itext-general.2136553.n4.nabble.com/Inline-image-parsing-issue-td2260626.html
>>
>> http://itext-general.2136553.n4.nabble.com/Re-not-expected-at-file-pointer-23512-td2172514.html
>>
>>
>> When I try to parse a PDF that opens nicely in Acrobat Reader, I'm
>> getting an exception InvalidPdfException: '>' not expected at file
>> pointer 558  (see further down for full stack strace).
>>
>> What can I do about it? Can I fix the PDF in some way? how? Can I
>> patch the itext-5.0.2 sources somehow? Although it seems that this is
>> a known problem, I couldn't find a bug a request for enhancement in
>> the tracker on sourceforge. Shall I create one?
>>
>> Thanks for your help,
>>
>> Andreas Ebbert-Karroum,
>>
>> Full stacktrace:
>>
>> ExceptionConverter: com.itextpdf.text.exceptions.InvalidPdfException:
>> '>' not expected at file pointer 558
>>     at com.itextpdf.text.pdf.PRTokeniser.throwError(PRTokeniser.java:197)
>>     at com.itextpdf.text.pdf.PRTokeniser.nextToken(PRTokeniser.java:332)
>>     at
>> com.itextpdf.text.pdf.PdfContentParser.nextValidToken(PdfContentParser.java:194)
>>
>>     at
>> com.itextpdf.text.pdf.PdfContentParser.readPRObject(PdfContentParser.java:164)
>>
>>     at
>> com.itextpdf.text.pdf.DocumentFont.fillMetrics(DocumentFont.java:209)
>>     at
>> com.itextpdf.text.pdf.DocumentFont.processType0(DocumentFont.java:165)
>>     at com.itextpdf.text.pdf.DocumentFont.<init>(DocumentFont.java:146)
>>     at
>> com.itextpdf.text.pdf.CMapAwareDocumentFont.<init>(CMapAwareDocumentFont.java:79)
>>
>>     at
>> com.itextpdf.text.pdf.parser.PdfContentStreamProcessor$SetTextFont.invoke(PdfContentStreamProcessor.java:591)
>>
>>     at
>> com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.invokeOperator(PdfContentStreamProcessor.java:226)
>>
>>     at
>> com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.processContent(PdfContentStreamProcessor.java:380)
>>
>>     at
>> com.itextpdf.text.pdf.parser.PdfReaderContentParser.processContent(PdfReaderContentParser.java:41)
>>
>>     at
>> com.itextpdf.text.pdf.parser.PdfTextExtractor.getTextFromPage(PdfTextExtractor.java:73)
>>
>>     at
>> com.itextpdf.text.pdf.parser.PdfTextExtractor.getTextFromPage(PdfTextExtractor.java:88)
>>
>>
>
>
>
>
> ------------------------------
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>
> ------------------------------
>
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
>
> End of iText-questions Digest, Vol 50, Issue 23
> ***********************************************
>

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to