package cn.flightfeather.supervision.docx4j.simpleDemo;
import org.docx4j.XmlUtils;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.io.SaveToZipFile;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.samples.AbstractSample;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/**
* This sample demonstrates how the MergeDocx utility can
* be used to merge docx documents.
*
* The MergeDocx utility is a paid extension to docx4j.
* Purchases of this extension support the docx4j project.
* @see
* merging-word-documents blog post for more info, or
* @see www.plutext.com
* or email sales@plutext.com if you want to buy it.
*
* To run the utility, you simply pass it a list of the
* docx you want to merge; it returns a new pkg containing
* the merged documents.
*
* This example looks a little more complex, since it
* has to use reflection, so that docx4j can still be
* built by users who don't have the MergeDocx code.
*
*/
public class MergeDocx extends AbstractSample {
final static String BASE_DIR = System.getProperty("user.dir") + "/sample-docs/word/";
final static String[] sourceDocxNames = { "tables.docx", "Images.docx"};
static boolean save = true;
static String outputfilepath = System.getProperty("user.dir") +"OUT_MergeDocx.docx";
/**
* @param args
* @throws Docx4JException
*/
public static void main(String[] args) throws Docx4JException {
// Create list of docx packages to merge
List wmlPkgList=new ArrayList();
for (int i=0; i documentBuilder = Class.forName("com.plutext.merge.DocumentBuilder");
//Method method = documentBuilder.getMethod("merge", wmlPkgList.getClass());
Method[] methods = documentBuilder.getMethods();
Method method = null;
for (int j=0; j