import com.spire.doc.*;import com.spire.doc.documents.Paragraph;import com.spire.doc.fields.TextRange;import java.awt.*;import java.io.*;public class setSpacing { public static void main(String[] args)throws IOException { //Load the sample document Document document= new Document("Sample1.docx"); //Add a new paragraph and append the text Paragraph para = new Paragraph(document); TextRange textRange1 = para.appendText("Newly added paragraph and set the paragraph spacing and character spacing"); textRange1.getCharacterFormat().setTextColor(Color.blue); textRange1.getCharacterFormat().setFontSize(14); //Set the spacing before and after paragraph para.getFormat().setBeforeAutoSpacing(false); para.getFormat().setBeforeSpacing(10); para.getFormat().setAfterAutoSpacing(false); para.getFormat().setAfterSpacing(10); //Set the character spacing for (DocumentObject object :(Iterable) para.getChildObjects()) { TextRange textRange= (TextRange) object; textRange.getCharacterFormat().setCharacterSpacing(3f); } //Insert the paragraph document.getSections().get(0).getParagraphs().insert(2, para); //Save the document to file document.saveToFile("Result.docx", FileFormat.Docx); }}
输出结果

Spire.Doc for Java更新至v4.5.1,该版本支持验证文档的保护密码,增强了Word到PDF/HTML/SVG的转换功能,同时还修复了加载和合并文档等时出现的问题。具体细节如下:
新功能:
- 支持验证文档的保护密码
Document document = new Document(); document.loadFromFile(input); boolean checkResult = document.checkProtectionPassWord(password);
String input="input.docx"; Document doc = new Document(); doc.loadFromFile(input); String result = "AddDigitalSignature.docx"; doc.saveToFile(result, FileFormat.Docx, "gary.pfx", "e-iceblue");
整合所有格式API处理套包Spire.office for Java正在 火热销售中!联系客服立马1分钟了解全部咨询!
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!