td16 wrote:How can a docx file be generated based on an specific Word template (.dot). My guess is that this information is stored in docProps/app.xml?
I haven't done any work with .dotx files, but ... I just saved a document as a template (.dotx) in Word 2007, and opened it in package explorer.
It has the same parts as a normal .docx; app.xml has a Properties/Template entry, but all docs generated by Word have that.
The difference (now opening it using WinZip) is that in [Content_Types].xml, we have this entry for document.xml.
- Code: Select all
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml" />
So, what you need to do is open the .dotx file, manipulate the resulting package as you wish using docx4j, and then, before you save it, change that entry in [Content_Types].xml. Something like:
- Code: Select all
wordMLPackage.getContentTypeManager().addOverrideContentType(partUri, contentType)
td16 wrote:Also how can properties be set in docProps/custom.xml? Any example would help. thanks!
Assuming there is already org.docx4j.openpackaging.parts.DocPropsCustomPart docPropsCustomPart, you just:
- Code: Select all
docPropsCustomPart.setProperty(propName, propValue)
If it doesn't exist already, you create the part and add it to the document.
Here is an example of doing that, and populating it from an existing file (exception handling omitted):
- Code: Select all
public static void injectDocPropsCustomPart(WordprocessingMLPackage wordMLPackage) {
org.docx4j.openpackaging.parts.DocPropsCustomPart docPropsCustomPart = new org.docx4j.openpackaging.parts.DocPropsCustomPart();
java.io.InputStream is = new java.io.FileInputStream("/tmp/custompart.xml" );
docPropsCustomPart.unmarshal(is);
wordMLPackage.addTargetPart(docPropsCustomPart);
}
Please report back to the forum on how you go.
cheers .. Jason