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

首頁 > 編程 > C# > 正文

C#實現TIF圖像轉PDF文件的方法

2020-01-24 01:38:38
字體:
來源:轉載
供稿:網友

本文實例講述了C#實現TIF圖像轉PDF文件的方法。分享給大家供大家參考。具體實現方法如下:

這里介紹使用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);   // 創建一個文檔對象   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();// 關閉   }   // 關閉文檔對象,釋放資源   doc.Close();  }  public static void Main(string[] args)  {   tifToPdf(new string[]{@"C:/test.tif"},@"C:/test.pdf");  } }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久治县| 阿图什市| 汕头市| 富阳市| 大关县| 金华市| 虹口区| 溧阳市| 黄山市| 鹰潭市| 化州市| 义乌市| 广灵县| 西吉县| 岫岩| 穆棱市| 牟定县| 阳谷县| 济源市| 雷波县| 漠河县| 安泽县| 修文县| 土默特左旗| 通州区| 五常市| 攀枝花市| 金门县| 清水县| 水富县| 攀枝花市| 忻州市| 台江县| 广德县| 明星| 玉树县| 苍南县| 开阳县| 岑巩县| 泾源县| 囊谦县|