This article demonstrates how to apply a border around a set of charaters and how to apply a border around a whole paragraph, by using Spire.Doc for Java.
import com.spire.doc.Document; import com.spire.doc.FileFormat; import com.spire.doc.Section; import com.spire.doc.documents.BorderStyle; import com.spire.doc.documents.BreakType; import com.spire.doc.documents.Paragraph; import com.spire.doc.fields.TextRange; import java.awt.*; public class AddBorders { public static void main(String[] args) { //Create a Document instance Document doc = new Document(); //Add a section Section section = doc.addSection(); //Add a border to a set of characters Paragraph para = section.addParagraph(); TextRange tr = para.appendText("Spire.Doc for Java"); tr.getCharacterFormat().getBorder().setBorderType(BorderStyle.Single); tr.getCharacterFormat().getBorder().setColor(Color.BLACK); String text = " is a professional Java library specifically designed for developers to create, read, " + "write, convert and print Word document files on Java platform."; para.appendText(text); para.appendBreak(BreakType.Line_Break); //Add a border to a paragraph para = section.addParagraph(); String text2 = "A plenty of Word document processing tasks can be performed by Spire.Doc for Java, such as " + "creating, reading, editing, converting and printing Word documents." ; para.appendText(text2); para.getFormat().getBorders().setBorderType(BorderStyle.Single); para.getFormat().getBorders().setColor(Color.BLACK); //Save the document doc.saveToFile("AddBorder.docx", FileFormat.Docx_2013); } }