Skip to main content

Posts

Showing posts from July, 2019

Insert Content Controls into Word Document in Java

  Introduction Content controls are ideal for creating templates because content controls can help us fix the position of content, specify the kind of content (for example, a date, a picture, or text), and restrict or enable editing on content. In this article, I will demonstrate how to insert the following types of content controls into a Word document in Java. ·        Combo box ·        Check box ·        Text ·        Picture ·        Date picker ·        Drop-down list   Required library Free Spire.Doc for Java Before using the below code, we need to download Free Spire.Doc for Java and then import the Spire.Doc.jar file into our project. For maven project, you can refer this online tutorial to install Free Spire.Doc for Java from maven repository.   Code example import com.spire.doc.*; import com.spire.doc.documents.*; import com.spire.doc.fields.*; import java.util.Date; public class ContentControls {     public s

Extract Text and Images from Word Document in Java

In this blog, I’ll introduce an easy solution to extract text and images from a Word document within Java application. Required Library Free Spire.Doc for Java Before using the below code, we need to download  Free Spire.Doc for Java   and then import the Spire.Doc.jar file into our project. For maven project, you can refer this  online tutorial   to install Free Spire.Doc for Java from maven repository. Extract Text Free Spire.Doc for Java provides a getText method in Document class which we can use to get text from a Word document. import com.spire.doc.Document; import java.io.FileWriter; import java.io.IOException; public class ReadText{ public static void main(String[] args) throws IOException { //load Word document Document document = new Document(); document.loadFromFile( "C: \\ Users \\ Administrator \\ Desktop \\ sample.docx" ); //get text from document as string String text=do