rieckpil / blog-tutorials

:star: Codebase for various tutorials about Java, Spring Boot, AWS, Kotlin, and Testing
https://rieckpil.de/
MIT License
770 stars 759 forks source link

Export file docx by template using docx4j output auto add "generated with Docx4j on Wildfly" to the footer #150

Open thangnm11 opened 1 year ago

thangnm11 commented 1 year ago

Blog post you are referring to

link blog: https://rieckpil.de/howto-generate-documents-from-word-templates-with-docx4j-on-wildfly-14/ link src code: https://github.com/rieckpil/blog-tutorials/tree/master/generate-documents-from-word-templates-with-docx4j-on-wildfly14

Expected Behavior

Show by template input.docx without add more in footer

Current Behavior

Show in footer of file output.docx "generated with Docx4j on Wildfly"

Steps to Reproduce

lib maven pom.xml

org.docx4j docx4j-JAXB-Internal 8.0.0 org.docx4j docx4j-JAXB-ReferenceImpl 8.0.0 org.docx4j docx4j-JAXB-MOXy 8.0.0 org.docx4j docx4j-export-fo 8.0.0

code java: public static void generateDocxFileFromTemplate() throws Exception { // TODO - ref: https://github.com/rieckpil/blog-tutorials/tree/master/generate-documents-from-word-templates-with-docx4j-on-wildfly14 InputStream templateInputStream = new FileInputStream("C:\Users\thangnm\Desktop\template (1).docx");

    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(templateInputStream);

    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();

    VariablePrepare.prepare(wordMLPackage);

    HashMap<String, String> variables = new HashMap<>();
    variables.put("firstName", "userInformation.getFirstName()");
    variables.put("lastName", "userInformation.getLastName()");
    variables.put("salutation", "userInformation.getSalutation()");
    variables.put("message", "userInformation.getMessage()");

    documentPart.variableReplace(variables);

    String outputfilepath = "C:\\Users\\thangnm\\Desktop\\template (2).docx";
    FileOutputStream os = new FileOutputStream(outputfilepath);

    wordMLPackage.save(os);
    os.flush();
    os.close();
}

Please help me, thanks!!!

thangnm11 commented 1 year ago

@rieckpil Please help me, thanks!!!

rieckpil commented 4 months ago

@thangnm11 does the error still occur?