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.21k stars 372 forks source link

Trouble with Docx to PDF about table::Text Align #407

Open Laxse opened 4 years ago

Laxse commented 4 years ago
InputStream in = new FileInputStream("C:\\Users\\liangxiao01\\Desktop\\DC.docx");
OutputStream out = new FileOutputStream("C:\\Users\\liangxiao01\\Desktop\\testFile3.pdf");
PdfConverter.getInstance().convert(new XWPFDocument(in), out, options);

Executed with the following code, the results are not satisfactory expect graph1 graph get graph2 graph

version: fr.opensagres.poi.xwpf.converter.core-2.0.2.jar fr.opensagres.poi.xwpf.converter.pdf-2.0.2.jar fr.opensagres.xdocreport.itext.extension-2.0.2.jar

sachinpatil321 commented 4 years ago

Do we have any fix for above issue? I am also facing this same issue for PDF conversion.

holoc285 commented 4 years ago

Hi friend, Do you have any fix for above issue?, I'm also facing this issue

Thanks in advance

Laxse commented 4 years ago

Hi friend, Do you have any fix for above issue?, I'm also facing this issue

Thanks in advance

Sorry, Im also waiting for developer to solve this problem. 😂

thomass4t commented 3 years ago

I am also waiting for a solution. Problem can be reproduced easily by creating an empty word file and insert a table with content. It works with odt file but not with docx.

DeesarrolladoR commented 2 years ago

Hi friends,

I have the same problem as you

Is there any solution?

Laxse commented 2 years ago

Hi friends,

I have the same problem as you

Is there any solution?

too hard to wait I had change to use Spire.office to make Docx to PDF.

DeesarrolladoR commented 2 years ago

Hi,

I have solved my problems:

RowRenderData row; row = Rows.of(new String[]{"Text1", "Text2"}).create(); CellStyle cs = new CellStyle(); cs.setVertAlign(XWPFVertAlign.CENTER); row.getCells().get(0).setCellStyle(cs);

This code vertically aligns Text1

My problem was that the cell I was trying to align fell on a "page break" and in that case it is not able to align vertically.

I use \<dependency> \<groupId>com.deepoove\</groupId> \<artifactId>poi-tl\</artifactId> \<version>1.10.4\</version> \</dependency>

To prevent the texts from being written on top of the lines in general in the tables (as in the images), I have implemented:

private static void setTableSpacingAfter(TableRenderData table){
    ParagraphStyle ps = new ParagraphStyle();
    ps.setSpacingAfter(5.0);
    for(RowRenderData iRow:table.getRows()){
        for(CellRenderData iCell:iRow.getCells()){
            for(ParagraphRenderData iParagraph:iCell.getParagraphs()){
                if(!Util.esVacio(iParagraph.getParagraphStyle())) {
                    iParagraph.getParagraphStyle().setSpacingAfter(ps.getSpacingAfter());
                }else{
                    iParagraph.setParagraphStyle(ps);
                }
            }
        }
    }
}