Ah. So you don't want to spin-the-pages-contents-sideways, you want
landscape-vs-portrait.
"Rotation" isn't the word you want. You just want to change the page size from
8.5x11 to 11x8.5. By the way, Rectangle.rotate() doesn't really rotate the
page either, it swaps the width/height. In PDF, there's a concept of page
rotation indepentant of a page's physical dimensions, which can lead to all
manner of Interesting Confusion (and messy code for dealing with it).
I'm not sure that's an option... ah, this might work:
1) pdfDocument.setPageEmpty(true)
2) setPageSize() // set the size of the NEXT page
3) newPage() // blow out the current page because 'its empty', get the next
page size, carry forward
4) redraw everything from the current page with the new page size.
Not terribly efficient, but if you want to reflow stuff in a PDF, that's what
you'll have to do.
NOTE: setPageEmpty is package private, so you'll need to write a class in
com.itextpdf.text.pdf.
There's also a package private fitsPage(PdfTable table, float margin) function
that I believe you'll find Quite Handy. You should be able to capture the
PdfDocument from OnStartPage, and call methods on it that way. That or call
the package-private PdfWriter.getPdfDocument(). I just tweaked the source so
it's public rather than calling all this package-private stuff from a class I
stuffed into com.lowagie.text.pdf (this predates the itextpdf package, which
isn't saying much at this point).
--Mark Storer
Senior Software Engineer
Cardiff.com
#include <disclaimer>
typedef std::Disclaimer<Cardiff> DisCard;
-----Original Message-----
From: Ponzer, Phillip [mailto:phillip.pon...@garmin.com]
Sent: Tuesday, January 19, 2010 3:56 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Rotate Page After Adding Text to Document
And no, I'm not trying to shrink the page after the fact to fit its content.
Basically, what I'm doing is making a new PDF and populating it with all sorts
of content (text, tables, images) where I need to dynamically figure out
whether each page should be portrait or landscape (PageSize.LETTER or
PageSize.LETTER.rotate() respectively).
The only case where I am interested in changing a page to landscape is when I'm
about to add a table that has too many columns to be easily displayed on a
portrait-size page.
I suppose I either need a way to:
A.) rotate the current page I'm on (this is while I'm in the center of the
document) and then continue adding content
or
B.) figure out if what I'm about to add will "fit" on the current page
(portrait is default, so if the table is too wide then it would be better
suited on a landscape page).
a. Another example could be a table whose header row is too tall
I plan to work out your suggestion tomorrow, but I'd figure I'd leave some
specifics as to what I'm trying to do in case you or anyone else has any more
ideas.
Thanks,
Phillip
_____
From: Mark Storer [mailto:msto...@autonomy.com]
Sent: Tuesday, January 19, 2010 5:13 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Rotate Page After Adding Text to Document
Are you trying to shrink the page after the fact to fit its content?
I had to do that very thing just last week:
Step 1: Find out where the pages end:
Extend PdfPageEventHelper's onEndPage.
Cast the Document parameter to a PdfDocument, and call it's
getVerticalPosition( true ).
Store those "end of the page" values and save out the PDF file (to a
ByteArrayOutputStream in my case, but my files are relatively small)
Step 2:
Open the baos up in a PdfStamper and update the pages' media boxes based on the
information from step one. I suggest allowing for a margin. The position
returned from getVerticalPosition will give you the last *baseline* used, "g",
"j" and so forth (anything with a "decender") hang below that position.
Congratulations, you've turned your PDF into an HTML. Whee. (grumble
grumble... "want an HTML-like page? THEN USE HTML!" grumble grumble)
--Mark Storer
Senior Software Engineer
Cardiff.com
#include <disclaimer>
typedef std::Disclaimer<Cardiff> DisCard;
-----Original Message-----
From: Ponzer, Phillip [mailto:phillip.pon...@garmin.com]
Sent: Tuesday, January 19, 2010 2:58 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Rotate Page After Adding Text to Document
PDF (I'll take help over "looking witty" any day :P )
And the reason why I want to do this is because I don't know how much space the
text (or in my particular case, the table) takes up until it has been added to
the document.
Any thoughts?
Phillip
_____
From: Mark Storer [mailto:msto...@autonomy.com]
Sent: Tuesday, January 19, 2010 4:53 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Rotate Page After Adding Text to Document
Are we talking PDF || HTML || RTF here?
(replying "yes", "true", or "1", while witty, won't get you much help... fair
warning) ;)
--Mark Storer
Senior Software Engineer
Cardiff.com
#include <disclaimer>
typedef std::Disclaimer<Cardiff> DisCard;
-----Original Message-----
From: Ponzer, Phillip [mailto:phillip.pon...@garmin.com]
Sent: Tuesday, January 19, 2010 2:41 PM
To: itext-questions@lists.sourceforge.net
Subject: [iText-questions] Rotate Page After Adding Text to Document
Hello everyone, and thanks for your help with my previous question.
Here's another one:
Is it possible to rotate the page you just added text to?
For instance, we have a Document variable called "doc" whose PageSize is set to
PageSize.LETTER, and I add some text. Can I make the page where that text
appears on landscape (after adding the text)?
Thanks,
Phillip
_____
This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient. If you are not the intended recipient, please be
aware that any disclosure, copying, distribution or use of this e-mail or any
attachment is prohibited. If you have received this e-mail in error, please
contact the sender and delete all copies.
Thank you for your cooperation.
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
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/