Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Adriansun opened this issue Mar 9, 2024 · 9 comments

Comments

@Adriansun
Copy link

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
Copy link
Member

Any contribution are welcome!

@Adriansun
Copy link
Author

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
Copy link

xdx2599 commented May 7, 2024

image image

@xdx2599
Copy link

xdx2599 commented May 7, 2024

            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
Copy link
Author

@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
Copy link

            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
Copy link

xdx2599 commented May 29, 2024 via email

@cllershen
Copy link

----- 原始邮件 ----- 发件人: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
Copy link

xdx2599 commented May 29, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants