开发者

Setting Alignment for each Element when more than one Element added to a PDFPcell

开发者 https://www.devze.com 2023-04-02 18:18 出处:网络
In a table, I have a few cells that contain multiple elements. For Example, to indicate address , the cell may contain a phrase containing an \"ADDRESS:\" header Chunk followed by another chunk contai

In a table, I have a few cells that contain multiple elements. For Example, to indicate address , the cell may contain a phrase containing an "ADDRESS:" header Chunk followed by another chunk containing the actual address:

FROM:          开发者_开发技巧              -- Chunk 1 in Phrase

123 Main St, Some City, ST   -- Chunk 2 in Phrase

As of now, to align the cell contents, I am using the following code in the PDFPcell:

cell.VerticalAlignment = Element.ALIGN_MIDDLE; 

However, this aligns all of the cell contents to the middle of the cell. If I want to put Chunk 1 at TOP_LEFT and Chunk 2 at BOTTOM_LEFT, is it possible to achieve it with iTextSharp? Essentially, I am looking for a way to align various elements within a cell at different locations.


Unfortunately the only way to do what you want is to add a sub-table in place of your multiple chunks.

t.AddCell("Row 1");
PdfPTable subTable = new PdfPTable(1);
subTable.DefaultCell.VerticalAlignment = Element.ALIGN_TOP;
subTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
subTable.AddCell("Top Align");

subTable.DefaultCell.VerticalAlignment = Element.ALIGN_BOTTOM;
subTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
subTable.AddCell("Bottom Align");

t.AddCell(subTable);

doc.Add(t);
0

精彩评论

暂无评论...
验证码 换一张
取 消