C#實現(xiàn)TIF圖像轉(zhuǎn)PDF文件的方法
更新時間:2015年07月06日 16:23:48 作者:DTC2
這篇文章主要介紹了C#實現(xiàn)TIF圖像轉(zhuǎn)PDF文件的方法,涉及C#使用TIFtoPDF工具實現(xiàn)pdf文件轉(zhuǎn)換的技巧,需要的朋友可以參考下
本文實例講述了C#實現(xiàn)TIF圖像轉(zhuǎn)PDF文件的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
這里介紹使用TIFtoPDF的用法。該工具可以將多個TIF圖像文件合并成一個PDF文件
TIFtoPDF.rar文件點擊此處本站下載。
Program.cs文件如下:
using System; using System.Collections.Generic; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.pdf.codec; namespace TIFtoPDF { class Program { //將多個tif文件合并成一個pdf文件 private static void tifToPdf(IEnumerable<string> arr, string sFilePdf) { FileInfo _toFile = new FileInfo(sFilePdf); // 創(chuàng)建一個文檔對象 Document doc = new Document(PageSize.A3, 0, 0, 0, 0); int pages = 0; FileStream fs=new FileStream(sFilePdf,FileMode.OpenOrCreate); // 定義輸出位置并把文檔對象裝入輸出對象中 PdfWriter writer = PdfWriter.GetInstance(doc, fs); // 打開文檔對象 doc.Open(); foreach(string sFileTif in arr) { PdfContentByte cb = writer.DirectContent; RandomAccessFileOrArray ra = new RandomAccessFileOrArray(sFileTif); int comps = TiffImage.GetNumberOfPages(ra); for (int c = 0; c < comps; ++c) { Image img = TiffImage.GetTiffImage(ra, c + 1); if (img != null) { img.ScalePercent(7200f / img.DpiX, 7200f / img.DpiY); doc.SetPageSize(new Rectangle(img.ScaledWidth, img .ScaledHeight)); img.SetAbsolutePosition(0,0); cb.AddImage(img); doc.NewPage(); ++pages; } } ra.Close();// 關(guān)閉 } // 關(guān)閉文檔對象,釋放資源 doc.Close(); } public static void Main(string[] args) { tifToPdf(new string[]{@"C:\test.tif"},@"C:\test.pdf"); } } }
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
WinForm實現(xiàn)關(guān)閉按鈕不可用或隱藏的方法
這篇文章主要介紹了WinForm實現(xiàn)關(guān)閉按鈕不可用或隱藏的方法,很實用的功能,需要的朋友可以參考下2014-08-08C#實現(xiàn)Windows服務(wù)測試與調(diào)試
這篇文章介紹了C#實現(xiàn)Windows服務(wù)測試與調(diào)試的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-02-02C#利用OLEDB實現(xiàn)將DataTable寫入Excel文件中
這篇文章主要為大家詳細介紹了C#如何利用OLEDB實現(xiàn)將DataTable寫入Excel文件中,文中的示例代碼簡潔易懂,具有一定的借鑒價值,需要的可以參考一下2023-02-02