2010-08-24 120 views
3

有誰知道一個好的.NET庫將TIFF文件(可能是多頁)轉換爲PDF文件嗎?需要.NET庫將TIFF文件轉換爲PDF

TIFF文件存儲在文件共享中,並且PDF文件需要存儲在與TIFF文件相同的位置。

該工具應該用於轉換大量的TIFF文件。

回答

1

Sam Leffler的libtiff附帶各種命令行工具。其中之一,tiff2pdf.exe將TIFF(包括多頁TIFF)轉換爲PDF。

這不是一種選擇嗎?

+0

肯定地說,感謝 – 2010-08-31 09:22:57

3

你可以試試我們的LibTiff.Net這個庫。它是免費和開放源代碼(BSD許可證),並附帶tiff2pdf工具,可能正是你所需要的。

+0

的聯繫不工作正確的鏈接似乎是http://www.bitmiracle.com/libtiff/ 但無論如何它看起來不錯:-) – 2010-08-31 09:26:14

+0

這很奇怪。剛剛檢查 - 兩個鏈接都適合我。 – Bobrovsky 2010-08-31 15:17:29

2

我使用免費的iTextSharp庫來創建一個PDF,並將標準System.Drawing.Image對象插入到PDF中,每頁一個。 CreateCompressedImageStream只需使用System.Drawing.Image並將其保存爲黑白PNG以減小文件大小。

http://www.itextpdf.com/

public byte[] CreatePDF(IEnumerable<Image> images) 
    { 
     if (!images.Any()) 
     { 
      throw new ArgumentException("You haven't specified any images."); 
     } 

     var stream = new MemoryStream(); 
     using(var doc = new Document()) 
     { 
      PdfWriter.GetInstance(doc, stream); 
      doc.Open(); 

      int i = 0; 
      foreach (var image in images) 
      { 
       i++; 
       var docImage = iTextSharp.text.Image.GetInstance(this.CreateCompressedImageStream(image)); 
       docImage.ScaleToFit(doc.PageSize.Width, doc.PageSize.Height); 
       doc.Add(docImage); 

       if (i + 1 < images.Count()) 
       { 
        doc.NewPage(); 
       } 
      } 

      doc.Close(); 
     } 

     return stream.ToArray(); 
    } 

    private Stream CreateCompressedImageStream(Image image) 
    { 
     MemoryStream imageStream = new MemoryStream(); 

     var info = ImageCodecInfo.GetImageEncoders().FirstOrDefault(i => i.MimeType.ToLower() == "image/png"); 
     EncoderParameter colorDepthParameter = new EncoderParameter(Encoder.ColorDepth, 1L); 
     var parameters = new EncoderParameters(1); 
     parameters.Param[0] = colorDepthParameter; 

     image.Save(imageStream, info, parameters); 

     imageStream.Position = 0; 
     return imageStream; 
    } 
5

下面是使用PDFSharp

using System; 
using System.Collections.Generic; 
using System.Text; 
using PdfSharp.Drawing; 
using PdfSharp.Pdf; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      PdfDocument s_document = new PdfDocument(); 

      PdfPage page = s_document.AddPage(); 

      XGraphics gfx = XGraphics.FromPdfPage(page); 


      XImage image = XImage.FromFile(@"C:\Image.tif"); 

      page.Width = image.PointWidth; 
      page.Height = image.PointHeight; 

      gfx.DrawImage(image, 0, 0); 

      s_document.Save(@"C:\Doc.pdf"); 
     } 
    } 
} 
0

的System.Drawing.Imaging.Bitmap類將允許您打開一個多頁的TIFF和提取每個幀的例子。然後,您需要確定每幀中圖像的大小,創建該大小的PDF頁面,然後在這些頁面上繪製位圖。

我已經題爲「Convert A Multipage TIFF To PDF Using PDFOne .NET於2011年出版

.NET的文章中做只是事情對我們產品的Gnostice PDFOne .NET提供的圖像提取功能。任何PDF創作庫就能做。其餘作業的

免責聲明:。我對工作的Gnostice