-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #271 - Make nested table visible when keepTogether is set for p…
…aragraph * nested tables are not working with pdftables * iterate over elements in paragraph and add these as single cells * iterator is necessary, paragraph.getChunks doesn't contain the nested table
- Loading branch information
Showing
2 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
openpdf/src/test/java/com/lowagie/text/pdf/PdfDocumentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.lowagie.text.pdf; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import org.junit.jupiter.api.DynamicTest; | ||
import org.junit.jupiter.api.TestFactory; | ||
|
||
import com.lowagie.text.Element; | ||
import com.lowagie.text.Paragraph; | ||
|
||
class PdfDocumentTest { | ||
|
||
private static final String PARAGRAPH_TEXT_1 = "Text above table"; | ||
|
||
private static final String PARAGRAPH_TEXT_2 = "Text below table"; | ||
|
||
@TestFactory | ||
List<DynamicTest> testCreateWithAllElementsInOneCell() { | ||
final PdfPTable table = new PdfPTable(2); | ||
table.addCell("Lorem"); | ||
table.addCell("ipsum"); | ||
table.addCell("dolor"); | ||
table.addCell("sit"); | ||
|
||
final Paragraph mainParagraph = new Paragraph(); | ||
final Paragraph paragraph1 = new Paragraph(PARAGRAPH_TEXT_1); | ||
final Paragraph paragraph2 = new Paragraph(PARAGRAPH_TEXT_2); | ||
|
||
mainParagraph.add(paragraph1); | ||
mainParagraph.add(table); | ||
mainParagraph.add(paragraph2); | ||
|
||
PdfPTable result = PdfDocument.createInOneCell(mainParagraph.iterator()); | ||
return Arrays.asList( | ||
DynamicTest.dynamicTest("row size should be 1", () -> assertThat(result.getRows().size(), equalTo(1))), | ||
DynamicTest.dynamicTest("cell size should be 1", () -> { | ||
final PdfPCell[] cells = result.getRows().get(0).getCells(); | ||
assertThat(cells.length, equalTo(1)); | ||
}), | ||
DynamicTest.dynamicTest("elements in cell should be 5", () -> assertThat(getCellElements(result).size(), equalTo(5))), | ||
DynamicTest.dynamicTest("element text should be '" + PARAGRAPH_TEXT_1 + "'", | ||
() -> assertThat(getCellElements(result).get(0).getChunks().toString(), equalTo(paragraph1.toString()))), | ||
DynamicTest.dynamicTest("element should be table", () -> assertThat(getCellElements(result).get(2), equalTo(table))), | ||
DynamicTest.dynamicTest("element text should be '" + PARAGRAPH_TEXT_2 + "'", | ||
() -> assertThat(getCellElements(result).get(3).getChunks().toString(), equalTo(paragraph2.toString())))); | ||
} | ||
|
||
private List<Element> getCellElements(PdfPTable result) { | ||
PdfPCell firstCell = result.getRows().get(0).getCells()[0]; | ||
return firstCell.getColumn().compositeElements; | ||
} | ||
|
||
} |