admin管理员组文章数量:1355051
Steps to reproduce Description: I am developing in a Java application that uses itext and html2pdf to render PDF's. One of our PDF's is bugged and we found out that the issue can be reproduced using only itext components which leaves us to believe this is a bug in itext.
itext version: 9.1.0 - We found this issue in itext version 7.1.16 and can reproduce it up to version 9.1.0, the code example was developed using 9.1.0.
html2pdf version: 6.1.0
Code example
package .example;
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.kernel.colors.Color;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.borders.Border;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.font.FontProvider;
import com.itextpdf.layout.properties.UnitValue;
import java.io.File;
public class Main {
public static final String DEST = "./target/sandbox/tables/simple_table9.pdf";
public static void main(String[] args) throws Exception {
File file = new File(DEST);
file.getParentFile().mkdirs();
new Main().manipulatePdf(DEST);
}
protected void manipulatePdf(String dest) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
pdfDoc.setDefaultPageSize(PageSize.A4.rotate());
Document doc = new Document(pdfDoc);
doc.add(new Paragraph("With 3 columns:"));
UnitValue[] unitValues = new UnitValue[]{
new UnitValue(UnitValue.POINT, 80),
new UnitValue(UnitValue.POINT, -1),
new UnitValue(UnitValue.POINT, 70),
new UnitValue(UnitValue.POINT, 40),
new UnitValue(UnitValue.POINT, 50),
new UnitValue(UnitValue.POINT, 55),
new UnitValue(UnitValue.POINT, 50),
new UnitValue(UnitValue.POINT, 55)
};
ConverterProperties converterProperties = new ConverterProperties();
final FontProvider fontProvider = new DefaultFontProvider(false, false, false);
fontProvider.addFont(StandardFonts.HELVETICA_OBLIQUE);
fontProvider.addFont(StandardFonts.HELVETICA);
converterProperties.setFontProvider(fontProvider);
doc.setFontProvider(fontProvider);
PdfFont font = PdfFontFactory.createFont(StandardFonts.HELVETICA);
doc.setFont(font);
doc.setFontColor(Color.convertRgbToCmyk(new DeviceRgb(255, 0, 0)));
Table table = new Table(unitValues);
doc.setMargins(20, 0, 20, 0);
table.setFontSize(9F);
table.setFixedLayout();
table.useAllAvailableWidth();
table.setKeepTogether(true);
table.setMarginTop(5);
table.setMarginLeft(-25);
table.setPadding(0);
// ROW 1
table.addCell(createCell("1"));
table.addCell(createCell("Eerste lijn beschrijving"));
table.addCell(createCell(""));
table.addCell(createCell("m²"));
table.addCell(createCell("1.050,0000"));
table.addCell(createCell("42.000,00"));
table.addCell(createCell("20.0%"));
table.addCell(createCell("52.500,00"));
// ROW 2
table.addCell(createCell(""));
table.addCell(createCell("Administratie").simulateItalic());
table.addCell(createCell("27.Structuurelementen staal").simulateItalic());
table.addCell(createCell("pallet").simulateItalic());
table.addCell(createCell("1.050,0000").simulateItalic());
table.addCell(createCell("42.000,00").simulateItalic());
table.addCell(createCell("20.0%").simulateItalic());
table.addCell(createCell("52.500,00").simulateItalic());
// ROW 2
// table.addCell(createCell(""));
// table.addCell(createCell("Administratie"));
// table.addCell(createCell("27.Structuurelementen staal"));
// table.addCell(createCell("pallet"));
// table.addCell(createCell("1.050,0000"));
// table.addCell(createCell("42.000,00"));
// table.addCell(createCell("20.0%"));
// table.addCell(createCell("52.500,00"));
// ROW 3
table.addCell(createCell("27.22"));
table.addCell(createCell("staalconstructie - thermisch verzinkt profielstaal - buitenconstructie kantoor"));
table.addCell(createCell(""));
table.addCell(createCell("kg"));
table.addCell(createCell("1,0000"));
table.addCell(createCell("3.751,44"));
table.addCell(createCell("11.5%"));
table.addCell(createCell("4.239,13"));
// ROW 4
table.addCell(createCell(""));
table.addCell(new Cell().add(new Paragraph("aankoop basismateriaal")).setPaddingLeft(15F).setBorder(Border.NO_BORDER));
table.addCell(createCell("27.Structuurelementen staal"));
table.addCell(createCell("kg"));
table.addCell(createCell("1,0500"));
table.addCell(createCell("0,91"));
table.addCell(createCell("11.5%"));
table.addCell(createCell("1,03"));
doc.add(table);
doc.close();
}
private Cell createCell(String text) {
var cell = new Cell(1, 1).setKeepTogether(true).setBorder(Border.NO_BORDER);
cell.add(new Paragraph(text));
return cell;
}
}
Expected behavior There is a total of 4 rows in this table, I expect them to be placed on one page, right after each other without any page breaks between the table.
Actual behavior After the first line, a page break is added. The remaining 3 rows are placed on the next page.
This only happens if the text is italic.
Steps to reproduce Description: I am developing in a Java application that uses itext and html2pdf to render PDF's. One of our PDF's is bugged and we found out that the issue can be reproduced using only itext components which leaves us to believe this is a bug in itext.
itext version: 9.1.0 - We found this issue in itext version 7.1.16 and can reproduce it up to version 9.1.0, the code example was developed using 9.1.0.
html2pdf version: 6.1.0
Code example
package .example;
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.kernel.colors.Color;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.borders.Border;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.font.FontProvider;
import com.itextpdf.layout.properties.UnitValue;
import java.io.File;
public class Main {
public static final String DEST = "./target/sandbox/tables/simple_table9.pdf";
public static void main(String[] args) throws Exception {
File file = new File(DEST);
file.getParentFile().mkdirs();
new Main().manipulatePdf(DEST);
}
protected void manipulatePdf(String dest) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
pdfDoc.setDefaultPageSize(PageSize.A4.rotate());
Document doc = new Document(pdfDoc);
doc.add(new Paragraph("With 3 columns:"));
UnitValue[] unitValues = new UnitValue[]{
new UnitValue(UnitValue.POINT, 80),
new UnitValue(UnitValue.POINT, -1),
new UnitValue(UnitValue.POINT, 70),
new UnitValue(UnitValue.POINT, 40),
new UnitValue(UnitValue.POINT, 50),
new UnitValue(UnitValue.POINT, 55),
new UnitValue(UnitValue.POINT, 50),
new UnitValue(UnitValue.POINT, 55)
};
ConverterProperties converterProperties = new ConverterProperties();
final FontProvider fontProvider = new DefaultFontProvider(false, false, false);
fontProvider.addFont(StandardFonts.HELVETICA_OBLIQUE);
fontProvider.addFont(StandardFonts.HELVETICA);
converterProperties.setFontProvider(fontProvider);
doc.setFontProvider(fontProvider);
PdfFont font = PdfFontFactory.createFont(StandardFonts.HELVETICA);
doc.setFont(font);
doc.setFontColor(Color.convertRgbToCmyk(new DeviceRgb(255, 0, 0)));
Table table = new Table(unitValues);
doc.setMargins(20, 0, 20, 0);
table.setFontSize(9F);
table.setFixedLayout();
table.useAllAvailableWidth();
table.setKeepTogether(true);
table.setMarginTop(5);
table.setMarginLeft(-25);
table.setPadding(0);
// ROW 1
table.addCell(createCell("1"));
table.addCell(createCell("Eerste lijn beschrijving"));
table.addCell(createCell(""));
table.addCell(createCell("m²"));
table.addCell(createCell("1.050,0000"));
table.addCell(createCell("42.000,00"));
table.addCell(createCell("20.0%"));
table.addCell(createCell("52.500,00"));
// ROW 2
table.addCell(createCell(""));
table.addCell(createCell("Administratie").simulateItalic());
table.addCell(createCell("27.Structuurelementen staal").simulateItalic());
table.addCell(createCell("pallet").simulateItalic());
table.addCell(createCell("1.050,0000").simulateItalic());
table.addCell(createCell("42.000,00").simulateItalic());
table.addCell(createCell("20.0%").simulateItalic());
table.addCell(createCell("52.500,00").simulateItalic());
// ROW 2
// table.addCell(createCell(""));
// table.addCell(createCell("Administratie"));
// table.addCell(createCell("27.Structuurelementen staal"));
// table.addCell(createCell("pallet"));
// table.addCell(createCell("1.050,0000"));
// table.addCell(createCell("42.000,00"));
// table.addCell(createCell("20.0%"));
// table.addCell(createCell("52.500,00"));
// ROW 3
table.addCell(createCell("27.22"));
table.addCell(createCell("staalconstructie - thermisch verzinkt profielstaal - buitenconstructie kantoor"));
table.addCell(createCell(""));
table.addCell(createCell("kg"));
table.addCell(createCell("1,0000"));
table.addCell(createCell("3.751,44"));
table.addCell(createCell("11.5%"));
table.addCell(createCell("4.239,13"));
// ROW 4
table.addCell(createCell(""));
table.addCell(new Cell().add(new Paragraph("aankoop basismateriaal")).setPaddingLeft(15F).setBorder(Border.NO_BORDER));
table.addCell(createCell("27.Structuurelementen staal"));
table.addCell(createCell("kg"));
table.addCell(createCell("1,0500"));
table.addCell(createCell("0,91"));
table.addCell(createCell("11.5%"));
table.addCell(createCell("1,03"));
doc.add(table);
doc.close();
}
private Cell createCell(String text) {
var cell = new Cell(1, 1).setKeepTogether(true).setBorder(Border.NO_BORDER);
cell.add(new Paragraph(text));
return cell;
}
}
Expected behavior There is a total of 4 rows in this table, I expect them to be placed on one page, right after each other without any page breaks between the table.
Actual behavior After the first line, a page break is added. The remaining 3 rows are placed on the next page.
This only happens if the text is italic.
Share Improve this question asked Mar 31 at 12:23 robaws_developerrobaws_developer 1 New contributor robaws_developer is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1- 2 you may indeed have found a bug @robaws_developer. we're looking into it, and I'll get back to you once we have something. – André Lemos Commented Mar 31 at 15:26
1 Answer
Reset to default 1This is indeed a bug. The cell content can't be broken anywhere and exceeds the space horizontally. Basically you can:
allocate more space for this column.
do not fix the width for this column.
pre-calculate minimum required column width using the content and the font.
The fix in iText Core won't help you much I believe as you will see something like this as the result
版权声明:本文标题:itext - Table bug report: when the content width overflows the column a page break is added - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743948455a2566845.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论