Dies ist, was ich bekomme. Wie kann ich den Tisch auch drehen - nicht nur das Dokument. Die Spalten könnten breiter sein, wenn der Tisch gedreht wurde. Ändern Sie die Ausrichtung von iText PdfPTable
Der folgende Code reproduziert das Problem in einem kleineren Maßstab mit nur 1 Spalte.
private void exportTableAsPDF(File outputFile) {
// PDF document
Document pdfDocument = new Document();
try {
PdfWriter pdfWriter = PdfWriter.getInstance(pdfDocument, new FileOutputStream(outputFile));
// Used to rotate the page - iText recommended this approach in an answer to a question referenced below
// https://developers.itextpdf.com/question/how-rotate-page-while-creating-pdf-document
class RotateEvent extends PdfPageEventHelper {
public void onStartPage(PdfWriter writer, Document document) {
writer.addPageDictEntry(PdfName.ROTATE, PdfPage.SEASCAPE);
}
}
// Rotates each page to landscape
pdfWriter.setPageEvent(new RotateEvent());
} catch (Exception e) {
e.printStackTrace();
}
pdfDocument.open();
// PDF table
PdfPTable pdfPTable = new PdfPTable(1);
// Add column header cell
PdfPCell dateCell = new PdfPCell(new Phrase("Date"));
pdfPTable.addCell(dateCell);
// Gets cell data
LogEntryMapper logEntryMapper = new LogEntryMapper();
List<LogEntry> logEntries = logEntryMapper.readAll();
// Adds a cell to the table with "date" data
for (LogEntry logEntry : logEntries) {
dateCell = new PdfPCell(new Phrase(logEntry.getLogEntryDate()));
pdfPTable.addCell(dateCell);
}
// Adds the table to the pdf document
try {
pdfDocument.add(pdfPTable);
} catch (DocumentException e) {
e.printStackTrace();
}
pdfDocument.close();
}
Dieser Codeblock erzeugt das folgende Ergebnis.
Bitte zeigen Sie uns ein minimales Codebeispiel, das dieses Problem reproduziert. –
@JorisSchellekens Ich habe meinen Code pro Anfrage hinzugefügt. – Region39
Sie wollen also im Wesentlichen eine Landschaft Seite aufrecht gefüllt? – mkl