Page 1 of 1

Craete a doc in protected mode using docx4j

PostPosted: Fri Nov 07, 2014 9:42 pm
by aguna
Converted html to doc
using below code
Code: Select all
String stringFromFile = FileUtils.readFileToString(new File(destFolder
            + "/" + xhtmlFileName), "UTF-8");
      WordprocessingMLPackage docxOut = WordprocessingMLPackage
            .createPackage();

      NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
      docxOut.getMainDocumentPart().addTargetPart(ndp);
      ndp.unmarshalDefaultNumbering();
      XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(docxOut);
      XHTMLImporter.setHyperlinkStyle("Hyperlink");
      docxOut.getMainDocumentPart().getContent()
            .addAll(XHTMLImporter.convert(stringFromFile, null));


      docxOut.save(new java.io.File(destFolder + "/" + docxFileName));

Conversion is success.
Need to create it in protected mode,so using below code
Code: Select all
DocumentSettingsPart dsp = wordMLPackage.getMainDocumentPart().getDocumentSettingsPart();
         ObjectFactory factory = new ObjectFactory();
         CTDocProtect protection = factory.createCTDocProtect();
         protection.setEdit(STDocProtect.READ_ONLY);
         protection.setEnforcement(true);
         dsp.getContents().setDocumentProtection(protection);

dsp.getcontent coming as null.Kindly let me know whether i m missing anything

Re: Craete a doc in protected mode using docx4j

PostPosted: Mon Nov 10, 2014 2:10 pm
by aguna
Kindly some one reply.i want that to be done imme7diately

Re: Craete a doc in protected mode using docx4j

PostPosted: Tue Nov 11, 2014 1:04 pm
by jason
Please note that community level support in this forum is on an "as we feel like it" basis. If you want commercial grade support, you can buy it from Plutext; see plutext.com for details.

That said, does the DocumentSettingsPart dsp exist? If not, you need to create and add it.

Assuming DocumentSettingsPart dsp exists, it looks like its content is not set.

So you need something like:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                dsp.setContents(new CTSettings());
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4