views:

35

answers:

2

Hi Everyone

Is there a quick and simple way to center align objects within the Document object? Without performing any calculation logic, ie. Get width of page, get width of contents, divide by two, etc.

I have a PdfPTable object within a Paragraph object, within the Document object. I would like to center the Paragraph object.

Thanks!

+1  A: 

this iText (probably same for iTextSharp):

paragraph.setAlignment( Element.ALIGN_CENTER );

and you might want to set the indentation so that it sits nicely:

paragraph.setIndentationLeft( 100 );
paragraph.setIndentationRight( 100 );
Steve Claridge
@Steve Claridge, It seems to be squishing the table. Do you have a way to stop it from doing so?
Idealflip
are you using the two setIndentation methods above? Reduce the indentation sizes or remove them completely.
Steve Claridge
PDFPTable has setWidthPercentage and setTotalWidth methods, which may help you
Steve Claridge
@Steve Claridge, thanks for the suggestions. The indentation methods seem to squish the tables themselves. I did try the setWidthPercentage and setTotalWidth methods as you suggested, but they weren't the exact solutions I was looking for. I'm actually onto another scenario now, where I'm trying to set the paragraph width to the width of the gridview from which it's populated, but I'm having some issues. Please see my other question if you get the chance. Thanks!
Idealflip
Here's my other question, http://stackoverflow.com/questions/3928015/itextsharp-paragraph-size
Idealflip