原創(chuàng)|使用教程|編輯:李顯亮|2020-12-24 11:05:13.657|閱讀 1211 次
概述:Spire系列文檔處理API是國(guó)產(chǎn)開(kāi)發(fā)工具中功能可媲美Aspose的強(qiáng)大控件,幫助開(kāi)發(fā)者輕松將文檔功能集成到應(yīng)用程序中。年終福利,小編為您傾情獻(xiàn)上Spire.DOC在Java中格式轉(zhuǎn)換的示例教程,記得收藏哦!
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
將文檔從一種格式轉(zhuǎn)換為另一種格式是Spire.DOC的主要功能之一。這種轉(zhuǎn)換只不過(guò)是加載和保存操作的組合。因此,使用Spire.DOC可以將文檔從任何受支持的加載格式轉(zhuǎn)換為任何受支持的保存格式。
本文整理了包括在Java中以下文件格式的轉(zhuǎn)換指南,希望對(duì)您有所幫助:
>>你可以點(diǎn)擊這里下載Spire.DOC for Java測(cè)試體驗(yàn)。
//create a Document object Document doc = new Document(); //load a Word file doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.docx"); //loop through the pages for (int i = 0; i < doc.getPageCount(); i++) { //save the specific page to a BufferedImage BufferedImage image= doc.saveToImages(i, ImageType.Bitmap); //write the image data to a .png file File file = new File( "output/" + String.format(("Img-%d.png"), i)); ImageIO.write(image, "PNG", file); }
import com.spire.doc.Document; import com.spire.doc.FileFormat; import com.spire.doc.ToPdfParameterList; public class WordToPDF { public static void main(String[] args) { //Create Document object Document doc = new Document(); //Load the file from disk. doc.loadFromFile("Sample.docx"); //create an instance of ToPdfParameterList. ToPdfParameterList ppl=new ToPdfParameterList(); //embeds full fonts by default when IsEmbeddedAllFonts is set to true. ppl.isEmbeddedAllFonts(true); //set setDisableLink to true to remove the hyperlink effect for the result PDF page. //set setDisableLink to false to preserve the hyperlink effect for the result PDF page. ppl.setDisableLink(true); //Set the output image quality as 40% of the original image. 80% is the default setting. doc.setJPEGQuality(40); //Save to file. doc.saveToFile("output/ToPDF.pdf",FileFormat.PDF); } }
import com.spire.doc.*; import com.spire.doc.documents.XHTMLValidationType; public class htmlFileToWord { public static void main(String[] args) throws Exception { // Load the sample HTML file Document document = new Document(); document.loadFromFile("InputHtmlFile.html", FileFormat.Html, XHTMLValidationType.None); //Save to file document.saveToFile("Result.pdf",FileFormat.PDF); } }如果您有任何疑問(wèn)或需求,請(qǐng)隨時(shí),我們很高興為您提供查詢和咨詢。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn