C#實現 word、pdf、ppt 轉為圖片
public class Word2ImageConverter : IImageConverter { private bool cancelled = false; public event CbGeneric<int, int> ProgressChanged; public event CbGeneric ConvertSucceed; public event CbGeneric<string> ConvertFailed; public void Cancel() {if (this.cancelled) { return; } this.cancelled = true; } public void ConvertToImage(string originFilePath, string imageOutputDirPath) { this.cancelled = false; ConvertToImage(originFilePath, imageOutputDirPath,0, 0, null, 200); } /// <summary> /// 將Word文件轉換為圖片 /// </summary> /// <param name="wordInputPath">Word檔案路徑</param> /// <param name="imageOutputDirPath">圖片輸出路徑,如果為空,預設值為Word所在路徑</param> /// <param name="startPageNum">從PDF文件的第幾頁開始轉換,如果為0,預設值為1</param> /// <param name="endPageNum">從PDF文件的第幾頁開始停止轉換,如果為0,預設值為Word總頁數</param> /// <param name="imageFormat">設定所需圖片格式,如果為null,預設格式為PNG</param> /// <param name="resolution">設定圖片的畫素,數字越大越清晰,如果為0,預設值為128,建議最大值不要超過1024</param> private void ConvertToImage(string wordInputPath, string imageOutputDirPath, int startPageNum, int endPageNum, ImageFormat imageFormat, int resolution) { try { Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath); if (doc == null) { throw new Exception("Word檔案無效或者Word檔案被加密!"); } if (imageOutputDirPath.Trim().Length == 0) { imageOutputDirPath = Path.GetDirectoryName(wordInputPath); } if (!Directory.Exists(imageOutputDirPath)) { Directory.CreateDirectory(imageOutputDirPath); } if (startPageNum <= 0) { startPageNum = 1; } if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; } if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; } if (imageFormat == null) { imageFormat = ImageFormat.Png; } if (resolution <= 0) { resolution = 128; } string imageName = Path.GetFileNameWithoutExtension(wordInputPath); ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.Png); imageSaveOptions.Resolution = resolution; for (int i = startPageNum; i <= endPageNum; i++) { if (this.cancelled) { break; } MemoryStream stream = new MemoryStream(); imageSaveOptions.PageIndex = i - 1; string imgPath = Path.Combine(imageOutputDirPath, imageName) + "_" + i.ToString("000") + "." + imageFormat.ToString(); doc.Save(stream, imageSaveOptions); Image img = Image.FromStream(stream); Bitmap bm = ESBasic.Helpers.ImageHelper.Zoom(img, 0.6f); bm.Save(imgPath, imageFormat); img.Dispose(); stream.Dispose(); bm.Dispose(); System.Threading.Thread.Sleep(200); if (this.ProgressChanged != null) { this.ProgressChanged(i - 1, endPageNum); } } if (this.cancelled) { return; } if (this.ConvertSucceed != null) { this.ConvertSucceed(); } } catch (Exception ex) { if (this.ConvertFailed != null) { this.ConvertFailed(ex.Message); } } } }
相關推薦
java語言通過Aspose元件 實現word轉pdf、png、html..
:使用Aspose元件可以實現word向DOC, DOCX, OOXML, RTF HTML,OpenDocument, PDF,EPUB, XPS, SWF 轉換 由於基本方法都一樣,在此我只展示word轉pdf的功能 前期準備: MyEcl
C#實現 word、pdf、ppt 轉為圖片
public class Word2ImageConverter : IImageConverter { private bool cancelled = false; public event CbGeneric<int, int> Pr
C# web實現word 轉Html、office轉Html、pdf轉圖片 線上預覽檔案
改篇 pdf 預覽再本機沒問題,釋出再iis中 不行 ,(使用剪貼簿的問題..excel和word 可以,) 詳細配置及程式碼 word 轉Html 複製程式碼 1 /// <summary> 2 /// word轉成html 3
基於C實現Word Count 將字符數、單詞數、行數,統計結果以指定格式輸出到默認文件中
計算 具體實現 post 及其 sp2 註釋 程序設計 cnblogs 基本 基於C實現Word Count ---系統分析與設計課程個人項目作業 1. 項目地址: [gitee地址] (https://gitee.com/little-baby/WordCount-by-
Android應用內展示word、excel、pdf、ppt等檔案
筆者最近兩個專案裡頭都有需要展示檔案的功能,於是做了一番調研,發現asce1885給出一份方案,不過都是關於pdf的展示:http://www.jianshu.com/p/1bf49af6584d,顯然不符合筆者的要求,筆者的專案裡需要展示的檔案格式並不單一,後來經過一番搜尋最後敲定使用
java 實現word 轉PDF (採用第三方技術 IText、Poi、Jsoup)
先講講思路: 第一步:使用 poi 將word轉換成 html,這裡程式碼一搜一堆沒什麼好說的,千篇一律。 (值得注意的地方是IText 根據html生成pdf檔案的時候
Asp.net實現直接在瀏覽器預覽Word、Excel、PDF、Txt檔案(附原始碼)
publicstaticvoid Priview(System.Web.UI.Page p, string inFilePath, string outDirPath ="") { Microsoft.Office.Interop.Excel.Application excel =nul
Android中開啟本地doc、pdf、ppt、text等檔案功能的實現
工具程式碼 private void lookMtl(String Dname,String DdownPath,String format) { String path= Environment.getExternalStorageDi
java通過url線上預覽Word、excel、ppt、pdf、txt文件中的內容【只獲得其中的文字】
在頁面上顯示各種文件中的內容。在servlet中的邏輯 word: BufferedInputStream bis = null; URL url = null; HttpURLConnection httpUrl = null; // 建立連結 url
js點選按鈕下載圖片、word、pdf、excel等
html: <button class="download" onclick=" download('url')"> <i class="layui-icon layui-icon-download-circle"><
c++實現棧的push、pop、min
其實push和pop較為簡單,可以用陣列實現,但是要兼顧到min,所以得另找個簡單的方法。 思路是用兩個棧實現,一個為資料棧,一個是存放最小資料的棧,且先叫小數棧,小數棧為空或者插入的資料小於當前小數棧頂資料時,將當前插入資料插入小數棧,否則將小數棧頂資料繼續插入小數棧,這
【VS2015】c++實現windows系統版本、型別、語言識別
一、VS2015 新建專案->win32 控制檯應用程式 1.以下操作實現跨平臺 (1).配置屬性-常規-MFC的使用->使用標準Windows庫或者在靜態庫中使用MFC (2).配置屬性-c/c++-程式碼生成-執行庫->多執行緒(/MT) 二.
C#實現窗體拖動、不允許窗體拖動、任意控制元件執行時拖動
1、不允許窗體被拖動。即使點選藍色標題條。 程式碼片段,加入不想被拖動的窗體中即可 protectedoverridevoid WndProc(refMessage m) { base.WndProc(ref m);
使用Jacob批量轉換word為txt、pdf、xps、html、xml等文件
Jacob全稱位java com bridge,通過該外掛,可以使用Java語言編寫程式,呼叫COM、ActiveX元件來操作Windows本地程式。 參考一位網友的例子,我寫了一個程式,用來將word批量轉換為txt等格式的文件。 該程式核心部分,僅僅是呼叫了Jacob的
Tika文字提取工具的使用(word、pdf、excel等)
Tika是Apache的Lucene專案下面的子專案,在lucene的應用中可以使用tika獲取大批量文件中的內容來建立索引,非常方便,也很容易使用~ Tika的缺點就是都是依賴外部的jar包,導致jar包的重量太大,lucene的核心包只有1M,tika約20M,tika依賴的外部的jar包有多樣的功能,
使用Lucene對doc、docx、pdf、txt文件進行全文檢索功能的實現
這裡講一下使用Lucene對doc、docx、pdf、txt文件進行全文檢索功能的實現。 涉及到的類一共有兩個: LuceneCreateIndex,建立索引: package com.yhd.test.poi; import java.io.BufferedReader; impo
jasperreport實現Html、Pdf、Rtf、 Excel、Xml報表匯出
1.資料來源(JRDataSource) import java.util.ArrayList; import java.util.List; import lbc.report.baseqry.QryData; import lbc.report.bean.VioW
Apache tika -- 解析多種型別(word、pdf、txt 等)檔案!
http://cloudera.iteye.com/blog/737629 apache 是個偉大的組織。 在lucene 檢索 如火如荼時, apache不忘繼續努力,近期提供了對各種格式檔案進行解析的解決方案 -- apache旗下的tika. 雖然還沒有1.0版 , 但已經很好用: Jav
Java 轉PPT為圖片、PDF、SVG、XPS、ODP以及PPT和PPTX互轉
同一文件,在不同的文件檢視器或者編譯環境中,需要對該文件進行相應的格式轉換。下面的內容中,將介紹通過Java程式設計來實現PPT文件格式轉換的方法。 使用工具: Spire.Presentation for Java IntelliJ IDEA Jar檔案獲取及匯入: 方法1
[轉載]java實現word轉pdf
write 方法 class toolbar servlet 效果 app 文檔 實現 最近遇到一個項目需要把word 轉成pdf,百度了一下網上的方案有很多,比如虛擬打印、給word 裝擴展插件等,這些方案都依賴於ms word 程序,在java代碼中也得使用諸如jac