欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)文章

最新評論