Sample Program:2
import java.io.FileNotFoundException;
import java.io.IOException;
import org.jdom.JDOMException;
import com.j2docx.operations.DOCXHandler;
import com.j2docx.spray.BookmarkSprayer;
import com.j2docx.util.DocxHandlerException;
/*
* @author j2docx
* Demo for spraying image
/
public class ImageSpray {
public static void main(String[] args) {
try{
//for extraction
String docPath= "C:/demo/sample.docx";
String targetDirPath="C:/demo";
//for archiving
String extractedPath= "C:/demo/sample";
//Bookmark name
String bookmarkName="bm1";
DOCXHandler docxHandler= new DOCXHandler();
BookmarkSprayer BMSprayer= new BookmarkSprayer();
//Extracting docx to the targeted directory path
docxHandler.doExtract(docPath, targetDirPath);
//Spraying Image
BMSprayer.sprayImage(extractedPath, bookmarkName,70,180, "C:/images/sample_image.jpg");
//Archiving back to get docx file
docxHandler.doZip(extractedPath, docPath);
}
catch(DocxHandlerException dhe){
dhe.printStackTrace();
}
catch(FileNotFoundException fnf){
fnf.printStackTrace();
}
catch(IOException ioe){
ioe.printStackTrace();
}
catch(JDOMException jdome){
jdome.printStackTrace();
}
}
}
Sample Program:2
import java.io.FileNotFoundException;
import java.io.IOException;
import org.jdom.JDOMException;
import com.j2docx.operations.DOCXHandler;
import com.j2docx.spray.BookmarkSprayer;
import com.j2docx.util.DocxHandlerException;
/*
* @author j2docx
* Demo for spraying image
/
public class ImageSpray {
public static void main(String[] args) {
try{
//for extraction
String docPath= "C:/demo/sample.docx";
String targetDirPath="C:/demo";
//for archiving
String extractedPath= "C:/demo/sample";
//Bookmark name
String bookmarkName="bm1";
DOCXHandler docxHandler= new DOCXHandler();
BookmarkSprayer BMSprayer= new BookmarkSprayer();
//Extracting docx to the targeted directory path
docxHandler.doExtract(docPath, targetDirPath);
//Spraying Image
BMSprayer.sprayImage(extractedPath, bookmarkName,70,180, "C:/images /sample_image.jpg");
//Archiving back to get docx file
docxHandler.doZip(extractedPath, docPath);
}
catch(DocxHandlerException dhe){
dhe.printStackTrace();
}
catch(FileNotFoundException fnf){
fnf.printStackTrace();
}
catch(IOException ioe){
ioe.printStackTrace();
}
catch(JDOMException jdome){
jdome.printStackTrace();
}
}
}