I actually thought of something like that.  Building multiple PDFs where the 
first page has custom margins and remaining pages have standard margins.  The 
problem is that 90+% of my PDFs are tables with variable row counts and a few 
header lines.  I really want to stick with using doc.add(myTable) and let iText 
deal with page breaks and reprinting headers.  So even if I do what you’re 
suggesting, I’m still stuck with knowing when I’ve reached the end of page 1 so 
I can change my margins and move to page 2.

 

My example was overly simplified compared to my actual code…so there’s probably 
something “lost in translation”.

 

The punch line of it all is this:  it’s unsafe to change margins in page 
events, but page events are the only way to know when you cross page boundaries.

 

That means that changing the margins and moving to the next page have to happen 
back to back….

 

I’d have to do something like this:

 

Create doc

Add only enough content to fill page 1 // can’t use doc.add(myTable) cause it 
might be a big table

doc.setMargins(….) //change them to the standard margins

doc.newPage() //

add all remaining content

 

and I would assume that concat’ing these PDFs would noticeably increase file 
size, which would be bad for me.

 

I think this rule: - don't change margins in PdfDocument (in a page event), 
change them in
Document (not in a page event).



 

Would be better stated (unless I’m confused) as:

- don't change margins in a page event…regardless of what “document” object you 
have a handle to.  

 

 

From: John Renfrew [mailto:r...@btclick.com] 
Sent: Thursday, July 28, 2011 11:37 AM
To: itext-questions@lists.sourceforge.net
Subject: [iText-questions] Fwd: Document getBottomMargin() bug

 

What about a completely different solution?

Write the first 3 pages to PDF 1

Write the next 1 to PDF 2

Write the rest to PDF 3

Concatenate.

 

Or write 1..3,5..N to PDF 1

Write 4 to PDF 2

Do a special concatenate which reads 1..3, adds 4, adds the rest.

 

 


Sent while on the move


Begin forwarded message:

        From: "Jason Berk" <jb...@purduefed.com>
        Date: 28 July 2011 16:20:28 GMT+01:00
        To: "Post all your questions about iText here" 
<itext-questions@lists.sourceforge.net>
        Subject: Re: [iText-questions] Document getBottomMargin() bug
        Reply-To: Post all your questions about iText here 
<itext-questions@lists.sourceforge.net>

        So I now see where this is going be difficult.  It pretty easy to change
        margins, and then invoke "doc.newPage()".  The difficult part is
        reverting the following pages back to the standard margins.
        
        I know when I'm about to start a page that needs different margins.  I
        only want those new margins on that page.  Once I add enough content to
        fill that page, the next page should revert back to the standard
        margins.
        
        page 1 has standard margins
        page 2 has standard margins
        page 3 has standard margins
        Change my margins and do a page break
        page 4 has custom margins
           start adding content that may span multiple pages
        page 5..N needs to go back to standard margins (which is why I as using
        "onEndPage()" page event.)
        
        If I can't (safely) change my document margins in onEndPage(), how else
        can I know I've reached the end of page 4 and should reset my margins so
        they are active on page 5+?
        
        Hhmmmm....
        
        
        
        ----Original Message-----
        From: 1T3XT BVBA [mailto:i...@1t3xt.info] 
        Sent: Thursday, July 28, 2011 9:58 AM
        To: Post all your questions about iText here
        Subject: Re: [iText-questions] Document getBottomMargin() bug
        
        On 28/07/2011 15:42, Jason Berk wrote:
        
        

        Is the rule "once you change margins, top/bottom/left/right may not 

                return what you expect"?

        The rule is:
        - don't change margins in PdfDocument (in a page event), change them in
        Document (not in a page event).
        - if you change them in Document, do so before triggering the newPage()
        method.
        - the new margins will only be "active" on the next page.
        
        I don't have the time to adapt, compile and execute your example, but
        this should be avoided:
        
        public void onEndPage(PdfWriter writer, Document document) {
          doc.setMargins(LEFT, RIGHT, TOP, BIG_BOTTOM); }
        
        I see that you tried to work around the fact that document is actually a
        PdfDocument instance.
        This is inventive (it surprised me), but I don't think it's a good idea.
        Operations on the Document object trigger page events, and you're
        triggering operations on the Document inside page events.
        I wouldn't bet on the outcome of such a workaround.
        
        ------------------------------------------------------------------------
        ------
        Got Input?   Slashdot Needs You.
        Take our quick survey online.  Come on, we don't ask for help often.
        Plus, you'll get a chance to win $100 to spend on ThinkGeek.
        http://p.sf.net/sfu/slashdot-survey
        _______________________________________________
        iText-questions mailing list
        iText-questions@lists.sourceforge.net
        https://lists.sourceforge.net/lists/listinfo/itext-questions
        
        iText(R) is a registered trademark of 1T3XT BVBA.
        Many questions posted to this list can (and will) be answered with a
        reference to the iText book: http://www.itextpdf.com/book/ Please check
        the keywords list before you ask for examples:
        http://itextpdf.com/themes/keywords.php
        This is a transmission from Purdue Federal Credit Union (Purdue 
Federal) and is intended solely for its authorized recipient(s), and may 
contain information that is confidential and or legally privileged. If you are 
not an addressee, or the employee or agent responsible for delivering it to an 
addressee, you are hereby notified that any use, dissemination, distribution, 
publication or copying of the information contained in this email is strictly 
prohibited. If you have received this transmission in error, please notify us 
by telephoning (765)497-3328 or returning the email. You are then instructed to 
delete the information from your computer. Thank you for your cooperation.
        
        
        
------------------------------------------------------------------------------
        Got Input?   Slashdot Needs You.
        Take our quick survey online.  Come on, we don't ask for help often.
        Plus, you'll get a chance to win $100 to spend on ThinkGeek.
        http://p.sf.net/sfu/slashdot-survey
        _______________________________________________
        iText-questions mailing list
        iText-questions@lists.sourceforge.net
        https://lists.sourceforge.net/lists/listinfo/itext-questions
        
        iText(R) is a registered trademark of 1T3XT BVBA.
        Many questions posted to this list can (and will) be answered with a 
reference to the iText book: http://www.itextpdf.com/book/
        Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php


This is a transmission from Purdue Federal Credit Union (Purdue Federal) and is 
intended solely for its authorized recipient(s), and may contain information 
that is confidential and or legally privileged. If you are not an addressee, or 
the employee or agent responsible for delivering it to an addressee, you are 
hereby notified that any use, dissemination, distribution, publication or 
copying of the information contained in this email is strictly prohibited. If 
you have received this transmission in error, please notify us by telephoning 
(765)497-3328 or returning the email. You are then instructed to delete the 
information from your computer. Thank you for your cooperation.

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to