国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C# > 正文

C#實(shí)現(xiàn)TIF圖像轉(zhuǎn)PDF文件的方法

2019-10-29 21:41:39
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這篇文章主要介紹了C#實(shí)現(xiàn)TIF圖像轉(zhuǎn)PDF文件的方法,涉及C#使用TIFtoPDF工具實(shí)現(xiàn)pdf文件轉(zhuǎn)換的技巧,需要的朋友可以參考下

本文實(shí)例講述了C#實(shí)現(xiàn)TIF圖像轉(zhuǎn)PDF文件的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

這里介紹使用TIFtoPDF的用法。該工具可以將多個(gè)TIF圖像文件合并成一個(gè)PDF文件

TIFtoPDF.rar文件點(diǎn)擊此處本站下載。

Program.cs文件如下:

 

 
  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.IO; 
  4. using iTextSharp.text; 
  5. using iTextSharp.text.pdf; 
  6. using iTextSharp.text.pdf.codec; 
  7. namespace TIFtoPDF 
  8. class Program 
  9. //將多個(gè)tif文件合并成一個(gè)pdf文件 
  10. private static void tifToPdf(IEnumerable<string> arr, string sFilePdf) 
  11. FileInfo _toFile = new FileInfo(sFilePdf); 
  12. // 創(chuàng)建一個(gè)文檔對(duì)象 
  13. Document doc = new Document(PageSize.A3, 0, 0, 0, 0); 
  14. int pages = 0; 
  15. FileStream fs=new FileStream(sFilePdf,FileMode.OpenOrCreate); 
  16. // 定義輸出位置并把文檔對(duì)象裝入輸出對(duì)象中 
  17. PdfWriter writer = PdfWriter.GetInstance(doc, fs); 
  18. // 打開(kāi)文檔對(duì)象 
  19. doc.Open(); 
  20. foreach(string sFileTif in arr) 
  21. PdfContentByte cb = writer.DirectContent; 
  22. RandomAccessFileOrArray ra = new RandomAccessFileOrArray(sFileTif); 
  23. int comps = TiffImage.GetNumberOfPages(ra); 
  24. for (int c = 0; c < comps; ++c) 
  25. Image img = TiffImage.GetTiffImage(ra, c + 1); 
  26. if (img != null
  27. img.ScalePercent(7200f / img.DpiX, 7200f / img.DpiY); 
  28. doc.SetPageSize(new Rectangle(img.ScaledWidth, img 
  29. .ScaledHeight)); 
  30. img.SetAbsolutePosition(0,0); 
  31. cb.AddImage(img); 
  32. doc.NewPage(); 
  33. ++pages; 
  34. ra.Close();// 關(guān)閉 
  35. // 關(guān)閉文檔對(duì)象,釋放資源 
  36. doc.Close(); 
  37. public static void Main(string[] args) 
  38. tifToPdf(new string[]{@"C:/test.tif"},@"C:/test.pdf"); 

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 商水县| 延津县| 囊谦县| 临江市| 广汉市| 漳州市| 精河县| 观塘区| 尼木县| 林芝县| 石首市| 安顺市| 安塞县| 柳河县| 特克斯县| 宜黄县| 磐石市| 莎车县| 理塘县| 竹山县| 定西市| 荣昌县| 榆树市| 上林县| 汾阳市| 巩义市| 贵南县| 醴陵市| 特克斯县| 英吉沙县| 张家港市| 桂林市| 柘荣县| 鹿邑县| 友谊县| 宝坻区| 梁平县| 织金县| 长阳| 蒙城县| 马关县|