翻譯|使用教程|編輯:李顯亮|2021-05-25 09:50:25.467|閱讀 506 次
概述:本文介紹如何使用Spire.Doc for Java獲取Word文檔中指定圖片的坐標位置、圖片大小以及圖片的文字環繞方式等。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for Java 是一款專業的Java Word組件,開發人員使用它可以輕松地將Word文檔創建、讀取、編輯、轉換和打印等功能集成到自己的Java應用程序中。
本文介紹如何使用Spire.Doc for Java獲取Word文檔中指定圖片的坐標位置、圖片大小以及圖片的文字環繞方式等。可點擊此處下載最新版測試。
import com.spire.doc.*; import com.spire.doc.documents.DocumentObjectType; import com.spire.doc.documents.Paragraph; import com.spire.doc.fields.DocPicture; public class GetPictureDetails { public static void main(String[] args) { //加載Word測試文檔 Document doc = new Document(); doc.loadFromFile("測試.docx"); //遍歷section for (int a = 0; a<doc.getSections().getCount();a++) { Section section = doc.getSections().get(a); //遍歷paragraph段落 for (int b =0 ;b<section.getParagraphs().getCount();b++) { Paragraph paragraph = section.getParagraphs().get(b); //遍歷段落中的對象 for (int i = 0; i < paragraph.getChildObjects().getCount(); i++) { DocumentObject docobj = paragraph.getChildObjects().get(i); //判斷對象是否為圖片 if (docobj.getDocumentObjectType()== DocumentObjectType.Picture) { DocPicture picture = (DocPicture) docobj ; //獲取標題為“圖片1”的圖片 if (picture.getTitle().equals("圖片1")) { //獲取圖片坐標位置 float x = picture.getHorizontalPosition(); float y = picture.getVerticalPosition(); //獲取圖片寬度、高度 float width = picture.getWidth(); float height = picture.getHeight(); //獲取圖片文字環繞 String wrappingstyle = picture.getTextWrappingStyle().toString();//圖片文字環繞方式 String wrappingtype = picture.getTextWrappingType().toString();//環繞文字類型 System.out.println("坐標位置為: X =" + x + " Y=" + y + "\n 圖片寬:"+ width + " 圖片高:" + height + "\n 圖片的文字環繞方式:" + wrappingstyle + " 環繞文字類型:" + wrappingtype); } } } } } } }
輸出結果
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分鐘了解全部咨詢!
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn