久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

怎么使用Aspose.words在Java中將Word和圖像轉(zhuǎn)換為PDF

本篇內(nèi)容主要講解“怎么使用Aspose.words在Java中將Word和圖像轉(zhuǎn)換為PDF”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“怎么使用Aspose.words在Java中將Word和圖像轉(zhuǎn)換為PDF”吧!

創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營(yíng)銷推廣、網(wǎng)站重做改版、貴州網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、HTML5建站、商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為貴州等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

將Word文檔轉(zhuǎn)換為PDF

從Word到PDF的轉(zhuǎn)換是一個(gè)相當(dāng)復(fù)雜的過(guò)程,需要幾個(gè)計(jì)算階段。Aspose.Words布局引擎模仿了Microsoft Word的頁(yè)面布局引擎的工作方式,使PDF輸出文檔看起來(lái)與Microsoft Word中所看到的盡可能接近。使用Aspose.Words,您可以通過(guò)編程方式將文檔從DOC或DOCX格式轉(zhuǎn)換為PDF,而無(wú)需使用Microsoft Office。本文介紹了如何執(zhí)行此轉(zhuǎn)換。

請(qǐng)注意,文檔中的頁(yè)數(shù)會(huì)影響轉(zhuǎn)換時(shí)間。

將DOC或DOCX轉(zhuǎn)換為PDF

在Aspose.Words中從DOC或DOCX文檔格式轉(zhuǎn)換為PDF格式非常容易,只需兩行代碼即可完成:

  • 通過(guò)使用擴(kuò)展名指定文檔名稱,使用其構(gòu)造函數(shù)之一將文檔加載到 Document對(duì)象中。

  • 調(diào)用Document對(duì)象上的Document.Save方法 之一,并通過(guò)輸入擴(kuò)展名為“ .PDF”的文件名將所需的輸出格式指定為PDF。

下面的代碼示例演示如何使用Save方法將文檔從DOCX轉(zhuǎn)換為PDF:

// Load the document from disk.
Document doc = new Document(dataDir + "Template.doc");

// Save the document in PDF format.
dataDir = dataDir + "output.pdf";
doc.save(dataDir);

請(qǐng)注意,使用相同的技術(shù),可以將任何流程布局格式的文檔轉(zhuǎn)換為PDF格式。

轉(zhuǎn)換為各種PDF標(biāo)準(zhǔn)

Aspose.Words提供 PdfCompliace 枚舉以支持將DOC或DOCX轉(zhuǎn)換為各種PDF格式標(biāo)準(zhǔn)(例如PDF 1.7,PDF 1.5等)。下面的代碼示例演示如何將文檔轉(zhuǎn)換為PDF使用1.7 PdfSaveOptions 與符合PDF17:

// The path to the documents directory.
Document originalDoc = new Document(dataDir + "Document.docx");

// Provide PDFSaveOption compliance to PDF17
// or just convert without SaveOptions
PdfSaveOptions pso = new PdfSaveOptions();
pso.setCompliance(PdfCompliance.PDF_17);

originalDoc.save(dataDir + "Output.pdf", pso);
將圖像轉(zhuǎn)換為PDF

轉(zhuǎn)換為PDF不受Microsoft Word文檔格式的限制。Aspose.Words支持的任何格式,包括以編程方式創(chuàng)建的格式,都可以轉(zhuǎn)換為PDF。例如,我們可以將單頁(yè)圖像(例如JPEG,PNG,BMP,EMF或WMF)以及多頁(yè)圖像(例如TIFF和GIF)轉(zhuǎn)換為PDF。

下面的代碼示例演示如何將JPEG和TIFF圖像轉(zhuǎn)換為PDF:

//將指定格式的圖像轉(zhuǎn)換為PDF。
ConvertImageToPDF(dataDir +  “ Test.jpg ”,dataDir +  “ TestJpg_out.pdf ”);
ConvertImageToPDF(dataDir +  “ Test.tiff ”,dataDir +  “ TestTif_out.pdf ”);
/**
 * Converts an image to PDF using Aspose.Words for Java.
 *
 * @param inputFileName File name of input image file.
 * @param outputFileName Output PDF file name.
 * @throws Exception
 */
 public static void ConvertImageToPDF(String inputFileName, String outputFileName) throws Exception {
 // Create Aspose.Words.Document and DocumentBuilder.
 // The builder makes it simple to add content to the document.
 Document doc = new Document();
 DocumentBuilder builder = new DocumentBuilder(doc);
  
 // Load images from the disk using the appropriate reader.
 // The file formats that can be loaded depends on the image readers available on the machine.
 ImageInputStream iis = ImageIO.createImageInputStream(new File(inputFileName));
 ImageReader reader = ImageIO.getImageReaders(iis).next();
 reader.setInput(iis, false);
  
 // Get the number of frames in the image.
 int framesCount = reader.getNumImages(true);
  
 // Loop through all frames.
 for (int frameIdx = 0; frameIdx < framesCount; frameIdx++) {
 // Insert a section break before each new page, in case of a multi-frame image.
 if (frameIdx != 0)
 builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
  
 // Select active frame.
 BufferedImage image = reader.read(frameIdx);
  
 // We want the size of the page to be the same as the size of the image.
 // Convert pixels to points to size the page to the actual image size.
 PageSetup ps = builder.getPageSetup();
 ps.setPageWidth(ConvertUtil.pixelToPoint(image.getWidth()));
 ps.setPageHeight(ConvertUtil.pixelToPoint(image.getHeight()));
  
 // Insert the image into the document and position it at the top left corner of the page.
 builder.insertImage(
 image,
 RelativeHorizontalPosition.PAGE,
 0,
 RelativeVerticalPosition.PAGE,
 0,
 ps.getPageWidth(),
 ps.getPageHeight(),
 WrapType.NONE);
 }
  
 if (iis != null) {
 iis.close();
 reader.dispose();
 }
  
 doc.save(outputFileName);
 }

到此,相信大家對(duì)“怎么使用Aspose.words在Java中將Word和圖像轉(zhuǎn)換為PDF”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

文章標(biāo)題:怎么使用Aspose.words在Java中將Word和圖像轉(zhuǎn)換為PDF
URL鏈接:http://sd-ha.com/article34/jiiese.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、ChatGPT、品牌網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)網(wǎng)站建設(shè)、Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)