• No se han encontrado resultados

Gestión de los procesos de los servicios

1. Gestión de Servicios

1.2 Gestión de empresas de servicios

1.2.1 Gestión de los procesos de los servicios

I am usingPdfPTableto create a table in PDF. I have a single row in the table. In my row, the last column has data which has a height that needs more space than remaining height of the page. So the row is getting started from the next page while the table headers are on the previous page and there is large blank space below the header on the first page. Can anybody suggest how I can split the row over multiple pages?

Posted on StackOverflow onFeb 27, 2014 ¹⁷¹

By default, table rows aren’t split. iText will try to add a complete row to the current page, and if the row doesn’t fit, it will try again on the next page. Only if it doesn’t fit on the next page, it will split the row. This is the default behavior, so you shouldn’t be surprised by what you see in your application.

You can change this default behavior. There’s a method that will allow you to drop content that doesn’t match (this is not what you want) and there’s a method that will allow you to split rows when they don’t fit the current page (this is what you want).

The method you need is used in theHeaderFooter2 example¹⁷²:

PdfPTable table = getTable(...);

table.setSplitLate(false);

By default, the value ofsetSplitLate()istrue: iText will split rows as late as possible. By changing

this default tofalse, iText will split rows immediately.

How does a

PdfPCell’s height relate to the font size?

In iText, what is the minimum height of aPdfPCellfor which a given size of font text is visible. I mean is there any ratio betweenPdfPCelland font size? I am making a PDF with pages of size A3, A4 and A5. I need to know the relation betweenFontsize andPdfPCell minimum height, so that the text will be visible.

Posted on StackOverflow onSep 3, 2013 ¹⁷³ Different concepts are at play when adding text to a cell.

¹⁷¹http://stackoverflow.com/questions/22063845/table-row-is-getting-started-from-the-new-page-in-itext-pdf ¹⁷²http://itextpdf.com/examples/iia.php?id=87

• padding is the extra space inside the borders of the cell. It’s similar to the concept with the same name in HTML. You can change the padding of a cell with thesetPadding()method.

• leading is the space between two lines. Even when there’s only one line, this leading will be used to determine the baseline of the text. By default the leading is 1.5 times the font size. If you’re working in text mode, the leading of a cell is set using the setLeading();

you can define a fixed leading (fixedLeading), or a leading that depends on the font size

(multipliedLeading). This value is ignored if you’re working in composite mode. In composite

mode, the leading of the separateElements added to the cell is used.

• ascender and descender are two value that are font-specific. The ascender is a value that tells you how much space is needed above the baseline of the text; the descender is a value that tells you how much space is needed below the baseline of the text. You can tell iText to take these values into account with the methodssetUseAscender()andsetUseDescender().

So, if you want the cell to have a minimal size, you need to set the padding to 0, the leading to match the size of the font, and tell iText to use the ascender and descender value.

DISCLAIMER: in the past, we’ve received reports from customers that showed us that not all fonts contain the correct ascender and descender information. This needs to be fixed at the font level.

How to add a table to the bottom of the last page?

I have created table in a PDF document using iText. This works fine, but I don’t want to add the table at the current pointer in the page, I want to add the table at the bottom.

PdfPTable datatablebottom = new PdfPTable(8);

PdfPCell cell = new PdfPCell();

// add cells here

datatablebottom.setTotalWidth(PageSize.A4.getWidth()-70); datatablebottom.setLockedWidth(true);

document.add(datatablebottom);

Posted on StackOverflow onMar 9, 2014 ¹⁷⁴ You need to define the absolute width of your table:

datatable.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin()));

Then you need to replace the line:

document.add(datatablebottom);

with this one:

datatable.writeSelectedRows(0, -1,

document.left(document.leftMargin()),

datatable.getTotalHeight() + document.bottom(document.bottomMargin()),

writer.getDirectContent());

ThewriteSelectedRows()method draws the table at an absolute position. We calculate that position

by asking thedocumentfor its left margin (the x value) and by adding the height of the table to the

bottom margin of the document (the Y coordinate). We draw all rows (0 to -1).

How do setMinimumSize() and setFixedSize() interact?

Is it OK to callsetMinimumSize(15)on some cells in a row, andsetFixedSize(15)on the other cells of the same row?

What I would like is for iText to increase the row height to accommodate the text in the cells whose minimum height is set, while letting text in cells set to a fixed height clip. Is that what iText does?

If not, how do I achieve this? While we’re at it, am I correct that calling neither setMinimumSize()norsetFixedSize()is equivalent to callingsetMinimumSize(0), mean- ing that iText makes the cell as tall as it needs to be to accommodate the text?

Posted on StackOverflow onFeb 28, 2014 ¹⁷⁵

The value defined usingsetFixedHeight()always gets preference. If you usesetMinimumHeight()

andsetFixedHeight()in the same row, and you define a minimum height along with a fixed height,

the fixed height prevails.

• if the minimum height is set to 30pt and the fixed height is 60pt, the height will be 60pt, no matter how much content is added to the cell.

• if the minimum height is set to 60pt and the fixed height is 60pt, the height will be 60pt, no matter how much content is added to the cell.

• if the minimum height is set to 120pt and the fixed height is 60pt, the height will be 60pt, no matter how much content is added to the cell.

If different fixed heights are defined, the highest value is taken. For instance: if you have a row where one cell has a fixed height (e.g 120 pt) that is higher than the fixed height of another cell (e.g. 60 pt), then the highest value (in this case 120) prevails.

All of this is demonstrated in the FixedHeightCell¹⁷⁶example. Please take a look at the resulting PDF¹⁷⁷. In row D all the cells have a fixed height of 60 pt. In row E, most cells also have a fixed height of 60, but the cell in column 4 has a fixed height of 120, hence the height of the row is 120. Then there’s row F, with a fixed height of 60 pt and a minimum height of 120 pt. Although we add text that doesn’t fit the cell in column 2, the content is truncated.