'How to resize html content so it will fit in A4 pdf?
Having issue with setting content to A4 pdf because of it size. Things i've tried : overflow-wrap,word-wrap ,custom customSplitCharacter class,setting max width of html,table,body. Are there any ideas how to set pdf size so table will automatically fit into it (without scrolling)? My itext dependencies: itext7-core(7.1.13), html2pdf (3.0.2),itextpdf(5.5.13.2)
Pdfview:
Htmlview:

public byte[] testingGetPDFInByte() {
String html = new String(testing('', 1, 1,
Collections.emptyList()).toByteArray());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
WriterProperties writerProperties = new WriterProperties();
writerProperties.addXmpMetadata();
PdfWriter pdfWriter = new PdfWriter(baos, writerProperties);
PdfDocument pdfDoc = new PdfDocument(pdfWriter);
pdfDoc.setDefaultPageSize(PageSize.A4);
FontProvider fontProvider = new DefaultFontProvider(true, true, false);
genDocConfigProperties.getFontPaths().forEach(fontProvider::addFont);
ConverterProperties props = new ConverterProperties();
props.setFontProvider(fontProvider);
props.setImmediateFlush(false);
final com.itextpdf.layout.Document document = HtmlConverter.convertToDocument(html, pdfDoc, props);
document.flush();
document.close();
return baos.toByteArray();
}
Table part of html:
<xsl:variable name="stl" select="'border:1px solid black;padding:5px;page-break-inside:avoid;max-width:30px;word-wrap: break-word;vertical-align:top;'" />
<table style="border-collapse: collapse;margin:5px;table-layout: fixed;">
<tr style="{$stl}">
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">№</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">Дата прибытия</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">Станция отправления</span>
</td>
<td style="{$stl}" colspan="3">
<span style="font-weight: bold;">СС</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">Дата отправления</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">Станция отправления</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">Код операции</span>
</td>
<td style="{$stl}" colspan="3">
<span style="font-weight: bold;">Пассажир</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">Стоимость места</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">Номер места</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">Номер и тип привилегии</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">Дата продажи</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">Терминал</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">Билет</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">№ поезда</span>
</td>
<td style="{$stl}" rowspan="2">
<span style="font-weight: bold;">№ вагона</span>
</td>
</tr>
<tr style="{$stl}">
<td style="{$stl}">
<span style="font-weight: bold;">Код</span>
</td>
<td style="{$stl}">
<span style="font-weight: bold;">Описание</span>
</td>
<td style="{$stl}">
<span style="font-weight: bold;">Продажа</span>
</td>
<td style="{$stl}">
<span style="font-weight: bold;">ФИО</span>
</td>
<td style="{$stl}">
<span style="font-weight: bold;">Тип документа</span>
</td>
<td style="{$stl}">
<span style="font-weight: bold;">№ документа</span>
</td>
</tr>
<xsl:for-each select="responseTikets">
<tr style="{$stl}">
<td style="{$stl}">
<xsl:value-of select="position()" />
</td>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
