Menu

J2docx

Vinothkumar PT

Welcome to your wiki!

This is the default page, edit it as you see fit. To add a new page simply reference it within brackets, e.g.: [SamplePage].

The wiki uses Markdown syntax.

Project Admins:


Discussion

  • Vinothkumar PT

    Vinothkumar PT - 2012-10-27

    Screenshot thumbnail
    Point docx document and write

    J2DOCX-“Java to docx” is a java approach to write the contents programmatically over the Microsoft docx documents and to manipulate the document. This API comprises set of useful funtions to work with docx. The version 1.0 supports only writing of text and images.

     
  • Vinothkumar PT

    Vinothkumar PT - 2012-10-28

    Sample Programs:

    Sample Program:1
    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 text
    /
    public class TextSpray {
    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";
            //Text to be sprayed
            String value="Hello world";
            //Font style
            String style = "font-family:verdana;font-size:18;font-weight:bold;font-color:red;italic:true;uline:single";
    
            DOCXHandler docxHandler= new DOCXHandler();
            BookmarkSprayer BMSprayer= new BookmarkSprayer();
    
            //Extracting docx to the targeted directory path
            docxHandler.doExtract(docPath, targetDirPath);
    
            //Writing Text
            BMSprayer.sprayText(extractedPath, bookmarkName, value, style);
    
            //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();
        }
    }
    

    }

     

    Last edit: Vinothkumar PT 2012-10-28

Log in to post a comment.