Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#379 add a test that reproduces issue 379 #380

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.ArrayList;
import java.util.List;

import static java.util.stream.Collectors.joining;

/**
* A row in the table grid. The list of cells it maintains is always large
* enough to set a table cell at every position in the row. If there are no
Expand All @@ -48,4 +50,11 @@ public void splitColumn(int pos) {
TableCellBox current = _row.get(pos);
_row.add(pos+1, current == null ? null : TableCellBox.SPANNING_CELL);
}

public String toString() {
return getClass().getSimpleName() + ": [" + _row.stream()
.map(box -> String.valueOf(box))
.collect(joining("; ")) +
"]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ void setCellWidths(LayoutContext c)
endCol++;
}

// Dirty fix for Issue 379 (fixes the exception, but the resulting PDF is still invalid):
// if (endCol >= columnPos.length) continue;
int w = columnPos[endCol] - columnPos[j] - hspacing;
cell.setLayoutWidth(c, w);
cell.setX(columnPos[j] + hspacing);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.xhtmlrenderer.pdf;

import com.codeborne.pdftest.PDF;
import com.lowagie.text.DocumentException;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.xhtmlrenderer.resource.XMLResource;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringReader;

import static com.codeborne.pdftest.assertj.Assertions.assertThat;

public class MultipleTbodyWithPaginationTest {
private static final Logger log = LoggerFactory.getLogger(MultipleTbodyWithPaginationTest.class);

@Test
public void simplePdf() throws DocumentException, IOException {
String htmlContent = """
<html>
<head>
<style>
table{
-fs-table-paginate: paginate;
width: 100%;
}
tbody {
page-break-inside: avoid;
}
td {
border: 1px solid gray;
}
</style>
</head>

<body>
<table>
<tbody id="tbody-1">
<tr id="row-1.a">
<td rowspan="2" id="left-1">Left 1</td>
<td height="300px" id="right-1.a">Right 1.a</td>
</tr>
<tr id="row-1.b">
<td height="300px" id="right-1.b">Right 1.b</td>
</tr>
</tbody>
<tbody id="tbody-2">
<tr id="row-2.a">
<td rowspan="2" id="left-2">Left 2</td>
<td height="300px" id="right-2.a">Right 2.a</td>
</tr>
<tr id="row-2.b">
<td height="300px" id="right-2.b">Right 2.b</td>
</tr>
</tbody>
</table>
</body>
</html>
""";

File file = new File("target/multiple-tbody-with-pagination.pdf");
try (FileOutputStream o = new FileOutputStream(file)) {
ITextRenderer renderer = new ITextRenderer();
Document source = XMLResource.load(new StringReader(htmlContent)).getDocument();
renderer.createPDF(source, o);
}
log.info("Generated PDF: {}", file.getAbsolutePath());

PDF pdf = new PDF(file);
assertThat(pdf.text).isEqualTo("Left 1\nRight 1.a\nRight 1.b\nLeft 2\nRight 2.a\nRight 2.b");
}
}
Loading