Sample provided
When you say PdfDocument, do you mean
"writer.getDirectContent().getPdfDocument()"?
Before I forget to say it....THANK YOU for spending the time to help me
understand my issue and your willingness to share.
Jason
import java.io.File;
import java.io.FileOutputStream;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfWriter;
public class TestChangeMargins2 extends PdfPageEventHelper {
public static final float STANDARD_MARGIN = 36f;
public static final float CUSTOM_BOTTOM_MARGIN = 270f;
public static final Rectangle PAGE_SIZE =
PageSize.LETTER;
private PdfContentByte canvas;
public TestChangeMargins2() throws Exception {
Document doc = new Document(PAGE_SIZE);
PdfWriter writer =
PdfWriter.getInstance(doc, new FileOutputStream(new File(
"/home/jberk/desktop/test.pdf")));
writer.setPageEvent(this);
doc.open();
canvas = writer.getDirectContent();
addTable(doc);
// change next page margins
doc.setMargins(STANDARD_MARGIN,
STANDARD_MARGIN, STANDARD_MARGIN, CUSTOM_BOTTOM_MARGIN);
doc.newPage();
// before adding a table that may
crosses multiple page, change the margins back
doc.setMargins(STANDARD_MARGIN,
STANDARD_MARGIN, STANDARD_MARGIN, STANDARD_MARGIN);
ColumnText.showTextAligned(canvas,
Element.ALIGN_LEFT, new Phrase("top left corner"),
doc.left(), doc.top(), 0);
ColumnText.showTextAligned(canvas,
Element.ALIGN_RIGHT, new Phrase("top right corner"),
doc.right(), doc.top(), 0);
ColumnText.showTextAligned(canvas,
Element.ALIGN_LEFT, new Phrase("bottom left corner"),
doc.left(), doc.bottom(), 0);
ColumnText.showTextAligned(canvas,
Element.ALIGN_RIGHT, new Phrase("bottom right corner"),
doc.right(), doc.bottom(), 0);
addTable(doc);
doc.close();
}
private void addTable(Document doc) throws Exception {
PdfPTable table = new PdfPTable(1);
table.setWidthPercentage(50);
for (int i = 1; i <= 90; i++) {
table.addCell(new
Phrase("row: " + i));
}
doc.add(table);
}
@Override
public void onEndPage(PdfWriter writer, Document
document) {
canvas.setColorStroke(BaseColor.RED);
canvas.moveTo(document.left(),
document.bottom());
canvas.lineTo(document.left(),
document.top());
canvas.lineTo(document.right(),
document.top());
canvas.lineTo(document.right(),
document.bottom());
canvas.lineTo(document.left(),
document.bottom());
canvas.stroke();
}
public static void main(String[] args) {
try {
new
TestChangeMargins2();
} catch (Exception e) {
e.printStackTrace();
}
}
}
From: 1T3XT BVBA [mailto:i...@1t3xt.info]
Sent: Friday, July 29, 2011 11:47 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Fwd: Document getBottomMargin() bug
On 29/07/2011 17:36, Jason Berk wrote:
In other words, doc.bottom(..) will return the unit set by the most
recent setMargins(...), not the actual bottom of the document
OK, I see that the values of the current and the next margins are stored
in PdfDocument, NOT in Document.
If you want to add a voucher using the current margin, you'd need to
find a way to ask PdfDocument for its bottom margin.
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