opensagres / xdocreport

XDocReport means XML Document reporting. It's Java API to merge XML document created with MS Office (docx) or OpenOffice (odt), LibreOffice (odt) with a Java model to generate report and convert it if you need to another format (PDF, XHTML...).
https://github.com/opensagres/xdocreport
1.19k stars 368 forks source link

Apache POI document to PDF with table borders creates PDF with texts in cells positioned too low in the cells #640

Open Adriansun opened 3 months ago

Adriansun commented 3 months ago

Doing a convert from Apache POI document to a PDF document will result that the texts in the cells in tables are lower than the bottom border, even though in the original .dotx document that Apache POI use has cells with texts in the upper left corner. Using other things to update a document and saving the POI object to .dotx and .docx will result in good cells. It is just about converting the object to PDF that makes the cells not being in line with the original object. Is there a default position for cells when converting? Center center would be enough. Right now it looks wonky.

angelozerr commented 3 months ago

Any contribution are welcome!

Adriansun commented 3 months ago

Any contribution are welcome!

I do not know what to do. I am here because I do not know. It is your repository so fix it.

xdx2599 commented 1 month ago
image image
xdx2599 commented 1 month ago
            PdfOptions options = PdfOptions.create().fontEncoding("UTF-8");
            options.fontProvider((familyName, encoding, size, style, color) -> createFont(familyName, size, style, color));
            PdfConverter.getInstance().convert(document, out, options);
Adriansun commented 1 month ago

@xdx2599 Yes, that is the same that I get with English letters and numbers. Have tried to lift the content up in the cells, but it does not seem to work.

cllershen commented 1 month ago
            PdfOptions options = PdfOptions.create().fontEncoding("UTF-8");
            options.fontProvider((familyName, encoding, size, style, color) -> createFont(familyName, size, style, color));
            PdfConverter.getInstance().convert(document, out, options);

Let me tell you, baby. You can use POI to set the after property to avoid this situation. In the current situation where the author does not have the energy to maintain it, this should be the most appropriate method. Adding more water is necessary. I hope you can understand what I mean ,(让我来告诉你吧 宝贝 你可以使用poi设置after属性来避免这种情况 在如今作者没有精力去维护的情况下 这应该是最合适的方法 面多了加水 我希望你能明白我的意思)

xdx2599 commented 1 month ago

----- 原始邮件 ----- 发件人:Adriansun @.> 收件人:opensagres/xdocreport @.> 抄送人:xdx2599 @.>, Mention @.> 主题:Re: [opensagres/xdocreport] Apache POI document to PDF with table borders creates PDF with texts in cells positioned too low in the cells (Issue #640) 日期:2024年05月11日 01点09分

@xdx2599 Yes, that is the same that I get with English letters and numbers. Have tried to lift the content up in the cells, but it does not seem to work.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned. Message ID: @.***>

cllershen commented 1 month ago

----- 原始邮件 ----- 发件人:Adriansun @.> 收件人:opensagres/xdocreport @.> 抄送人:xdx2599 @.>, Mention @.> 主题:Re: [opensagres/xdocreport] Apache POI document to PDF with table borders creates PDF with texts in cells positioned too low in the cells (Issue #640) 日期:2024年05月11日 01点09分 @xdx2599 Yes, that is the same that I get with English letters and numbers. Have tried to lift the content up in the cells, but it does not seem to work. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned. Message ID: @.***>

NiceXWPFDocument xwpfDocument = template.getXWPFDocument(); for (int tableNum = 0; tableNum < xwpfDocument.getTables().size(); tableNum++) { if (tableNum == 0) continue; XWPFTable xwpfTable = xwpfDocument.getTables().get(tableNum); xwpfTable.getRows() .forEach(row -> { row.getTableCells().forEach( cell -> { cell.getParagraphs().forEach(xwpfParagraph -> { CTP ctp = xwpfParagraph.getCTP(); CTPPr ppr = ctp.isSetPPr() ? ctp.getPPr() : ctp.addNewPPr(); CTSpacing spacing = ppr.isSetSpacing()? ppr.getSpacing() : ppr.addNewSpacing(); spacing.setAfter(BigInteger.valueOf(40)); spacing.setBefore(BigInteger.valueOf(0)); spacing.setLineRule(lineRule); spacing.setLine(BigInteger.valueOf(lineSpacing)); }); }); }); }; it is my code it help me solve this problem,you can try it

xdx2599 commented 1 month ago

3Q 我也是用的同样的方法解决的 ----- 原始邮件 ----- 发件人:良良 陈 @.> 收件人:opensagres/xdocreport @.> 抄送人:xdx2599 @.>, Mention @.> 主题:Re: [opensagres/xdocreport] Apache POI document to PDF with table borders creates PDF with texts in cells positioned too low in the cells (Issue #640) 日期:2024年05月29日 09点39分

----- 原始邮件 ----- 发件人:Adriansun @.> 收件人:opensagres/xdocreport @.> 抄送人:xdx2599 @.>, Mention @.> 主题:Re: [opensagres/xdocreport] Apache POI document to PDF with table borders creates PDF with texts in cells positioned too low in the cells (Issue #640) 日期:2024年05月11日 01点09分 @xdx2599 Yes, that is the same that I get with English letters and numbers. Have tried to lift the content up in the cells, but it does not seem to work. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned. Message ID: @.***>

NiceXWPFDocument xwpfDocument = template.getXWPFDocument();

for (int tableNum = 0; tableNum < xwpfDocument.getTables().size(); tableNum++) {

if (tableNum == 0) continue;

XWPFTable xwpfTable = xwpfDocument.getTables().get(tableNum);

xwpfTable.getRows()

.forEach(row -> {

row.getTableCells().forEach( cell -> {

cell.getParagraphs().forEach(xwpfParagraph -> {

CTP ctp = xwpfParagraph.getCTP();

CTPPr ppr = ctp.isSetPPr() ? ctp.getPPr() : ctp.addNewPPr();

CTSpacing spacing = ppr.isSetSpacing()? ppr.getSpacing() : ppr.addNewSpacing();

spacing.setAfter(BigInteger.valueOf(40));

spacing.setBefore(BigInteger.valueOf(0));

spacing.setLineRule(lineRule);

spacing.setLine(BigInteger.valueOf(lineSpacing));

});

});

});

};

it is my code it help me solve this problem,you can try it

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>