Fix various issues with word/PDF export

This commit is contained in:
George Kalampokis 2021-11-02 18:06:00 +02:00
parent 39795f177f
commit db4d1006c6
2 changed files with 16 additions and 4 deletions

View File

@ -171,7 +171,7 @@ public class HtmlToWorldBuilder implements NodeVisitor {
break; break;
case "br": case "br":
if (stringBooleanEntry.getValue()) { if (stringBooleanEntry.getValue()) {
this.run.addCarriageReturn(); this.run.addBreak();
} }
break; break;
} }

View File

@ -52,8 +52,7 @@ public class WordBuilder {
}); });
this.options.put(ParagraphStyle.HTML, (mainDocumentPart, item) -> { this.options.put(ParagraphStyle.HTML, (mainDocumentPart, item) -> {
Document htmlDoc = Jsoup.parse(item.replaceAll("\n", "<br>")); Document htmlDoc = Jsoup.parse(item.replaceAll("\n", "<br>"));
HtmlToWorldBuilder htmlToWorldBuilder = HtmlToWorldBuilder.convert(mainDocumentPart, htmlDoc, 0.5F); HtmlToWorldBuilder htmlToWorldBuilder = HtmlToWorldBuilder.convert(mainDocumentPart, htmlDoc, 0.8F);
htmlToWorldBuilder.getParagraph().setIndentationLeft(0);
return htmlToWorldBuilder.getParagraph(); return htmlToWorldBuilder.getParagraph();
}); });
this.options.put(ParagraphStyle.TITLE, (mainDocumentPart, item) -> { this.options.put(ParagraphStyle.TITLE, (mainDocumentPart, item) -> {
@ -132,8 +131,16 @@ public class WordBuilder {
public XWPFDocument build(XWPFDocument document, PagedDatasetProfile pagedDatasetProfile, VisibilityRuleService visibilityRuleService) throws IOException { public XWPFDocument build(XWPFDocument document, PagedDatasetProfile pagedDatasetProfile, VisibilityRuleService visibilityRuleService) throws IOException {
createPages(pagedDatasetProfile.getPages(), document, true, visibilityRuleService); createPages(pagedDatasetProfile.getPages(), document, true, visibilityRuleService);
XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
XWPFNumbering numbering = document.createNumbering(); XWPFNumbering numbering = document.createNumbering();
BigInteger tempNumId = BigInteger.ONE;
boolean found = false;
while (!found) {
Object o = numbering.getAbstractNum(tempNumId);
found = (o == null);
if (!found) tempNumId = tempNumId.add(BigInteger.ONE);
}
cTAbstractNum.setAbstractNumId(tempNumId);
XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
BigInteger abstractNumID = numbering.addAbstractNum(abstractNum); BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
this.numId = numbering.addNum(abstractNumID); this.numId = numbering.addNum(abstractNumID);
createPages(pagedDatasetProfile.getPages(), document, false, visibilityRuleService); createPages(pagedDatasetProfile.getPages(), document, false, visibilityRuleService);
@ -252,13 +259,16 @@ public class WordBuilder {
} }
if (question) { if (question) {
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL); cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
cTLvl.addNewLvlText().setVal("");
cTLvl.setIlvl(BigInteger.valueOf(indent)); cTLvl.setIlvl(BigInteger.valueOf(indent));
} else if (!question && hasIndication) { } else if (!question && hasIndication) {
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL); cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
cTLvl.addNewLvlText().setVal("");
cTLvl.setIlvl(BigInteger.valueOf(indent)); cTLvl.setIlvl(BigInteger.valueOf(indent));
} }
if (!question && !hasIndication) { if (!question && !hasIndication) {
cTLvl.addNewNumFmt().setVal(STNumberFormat.NONE); cTLvl.addNewNumFmt().setVal(STNumberFormat.NONE);
cTLvl.addNewLvlText().setVal("");
cTLvl.setIlvl(BigInteger.valueOf(indent)); cTLvl.setIlvl(BigInteger.valueOf(indent));
} }
} }
@ -337,7 +347,9 @@ public class WordBuilder {
return data.getLabel(); return data.getLabel();
case "freetext": case "freetext":
case "datepicker": case "datepicker":
case "datePicker":
case "textarea": case "textarea":
case "richTextarea":
return field.getValue() != null ? field.getValue().toString(): ""; return field.getValue() != null ? field.getValue().toString(): "";
case "datasetIdentifier": case "datasetIdentifier":
case "validation": case "validation":