Слияние кода завершено, страница обновится автоматически
таблицей данные. Корректный перевод будет следующим: При последовательном создании двух таблиц, вторая таблица может частично перекрывать данные первой созданной таблицы.
Используемая версия:
org.dromara.x-easypdf
x-easypdf
3.2.1
public static void main(String[] args) {
Document document = PdfHandler.getDocumentHandler().create();
document.setMargin(20F);
Page page = new Page(document);
Table table = new Table(document.getCurrentPage());
// Ширина таблицы
float width = page.getWithoutMarginWidth() / 24;
float height = 20F;
table.setCellWidths(width * 3, width * 12, width * 3, width * 6);
table.setBackgroundColor(new Color(244, 249, 239));
table.setMarginTop(5f);
table.setIsBorder(true);
TableRow tableRow = new TableRow(table);
tableRow.setHeight(height);
tableRow.setContentVerticalAlignment(VerticalAlignment.CENTER);
// Номер
Textarea serialNumberTxt = new Textarea(document.getCurrentPage());
serialNumberTxt.setText("Номер:");
serialNumberTxt.setHorizontalAlignment(HorizontalAlignment.RIGHT);
serialNumberTxt.setFontColor(new Color(134, 5, 5));
TableCell serialNumberTxtCell = new TableCell(tableRow);
serialNumberTxtCell.addComponents(serialNumberTxt);
serialNumberTxtCell.setContentHorizontalAlignment(HorizontalAlignment.RIGHT);
// Номер
Textarea serialNumberVal = new Textarea(document.getCurrentPage());
serialNumberVal.setText("7e8f6a2b-9f32-42d8-b317-0b8cb20eb482");
serialNumberVal.setHorizontalAlignment(HorizontalAlignment.LEFT);
TableCell serialNumberValCell = new TableCell(tableRow);
serialNumberValCell.addComponents(serialNumberVal);
// Время проверки
Textarea detectionTimeTxt = new Textarea(document.getCurrentPage());
detectionTimeTxt.setHorizontalAlignment(HorizontalAlignment.RIGHT);
detectionTimeTxt.setFontColor(new Color(134, 5, 5));
TableCell detectionTimeTxtCell = new TableCell(tableRow);
detectionTimeTxtCell.addComponents(detectionTimeTxt);
detectionTimeTxtCell.setContentHorizontalAlignment(HorizontalAlignment.RIGHT);
// Время проверки
Textarea detectionTimeVal = new Textarea(document.getCurrentPage());
detectionTimeVal.setText("2023-09-12 16:45:00");
detectionTimeVal.setHorizontalAlignment(HorizontalAlignment.RIGHT);
TableCell detectionTimeValCell = new TableCell(tableRow);
detectionTimeValCell.addComponents(detectionTimeVal);
TableRow tableRow1 = new TableRow(table);
tableRow1.setHeight(height);
tableRow1.setContentVerticalAlignment(VerticalAlignment.CENTER);
// Отправившаяся на проверку организация
Textarea inspectionUnitTxt = new Textarea(document.getCurrentPage());
inspectionUnitTxt.setText("Отправившаяся на проверку организация:");
inspectionUnitTxt.setHorizontalAlignment(HorizontalAlignment.RIGHT);
inspectionUnitTxt.setFontColor(new Color(134, 5, 5));
TableCell inspectionUnitTxtCell = new TableCell(tableRow1);
inspectionUnitTxtCell.addComponents(inspectionUnitTxt);
inspectionUnitTxtCell.setContentHorizontalAlignment(HorizontalAlignment.RIGHT);
// Отправившаяся на проверку организация
Textarea inspectionUnitVal = new Textarea(document.getCurrentPage());
inspectionUnitVal.setText("тест тест");
inspectionUnitVal.setHorizontalAlignment(HorizontalAlignment.LEFT);
TableCell inspectionUnitValCell = new TableCell(tableRow1);
inspectionUnitValCell.addComponents(inspectionUnitVal);
tableRow.addCells(serialNumberTxtCell, serialNumberValCell, detectionTimeTxtCell, detectionTimeValCell);
tableRow1.addCells(inspectionUnitTxtCell, inspectionUnitValCell, new TableCell(tableRow1), new TableCell(tableRow1));
table.setRows(tableRow, tableRow1, tableRow1);
table.render();
Table tableInfo = new Table(document.getCurrentPage());
tableInfo.setIsBorder(true);
tableInfo.setCellWidths(24 * width);
TableRow tableRowInfo = new TableRow(tableInfo);
tableRowInfo.setHeight(height);
Textarea txtInfo = new Textarea(document.getCurrentPage());
txtInfo.setText("тест");
TableCell tableCell = new TableCell(tableRowInfo);
tableCell.addComponents(txtInfo);
tableRowInfo.addCells(tableCell);
tableInfo.addRows(tableRowInfo);
tableInfo.render();
document.appendPage(page);
document.save("D:\\ideaWork\\xCheckerV2\\smartGenReportPDFBox\\src\\test\\simpleContainerTest1.pdf");
document.close();
}