2012-07-25 80 views
0

我想从pdf文件,使用Itextsharp和Bitmiracle创建tif图像。试图从PDF创建Tif。越来越差的图像

首先,我想使用iTextsharp获取pdf文件每个页面的字节细节。

string bpp = pd.Get(PdfName.BITSPERCOMPONENT).ToString(); 
PixelFormat pixelFormat; 
switch (bpp) 
{ 
    case "1": 
     pixelFormat = PixelFormat.Format1bppIndexed; 
     break; 
    case "8": 
     pixelFormat = PixelFormat.Format24bppRgb; 
     break; 
    default: 
     throw new Exception(String.Format("Unknown pixel format {0}.", bpp)); 
} 

之后,使用bitmiracle我保存该图像在TIFF格式。但图像不可见。

string filter = PDFStremObj.Get(PdfName.FILTER).ToString(); 
switch (filter) 
{ 
    case "/FlateDecode": 

    byte[] arr = PdfReader.GetStreamBytes((PRStream)PDFStremObj); 

    Bitmap bmp = new Bitmap(Int32.Parse(width), Int32.Parse(height), PixelFormat.Format24bppRgb); 
    BitmapData bmd = bmp.LockBits(new System.Drawing.Rectangle(0, 0, Int32.Parse(width), Int32.Parse(height)), ImageLockMode.WriteOnly, 
      PixelFormat.Format24bppRgb); 
    Marshal.Copy(arr, 0, bmd.Scan0, arr.Length); 
    bmp.UnlockBits(bmd); 
    bmp.Save(strFileNewName, System.Drawing.Imaging.ImageFormat.Tiff); 
    bmp.Dispose(); 
    page++; 
    break; 
} 

请帮我解决代码中的问题,或者建议我更改。

在此先感谢您的帮助。

+0

为什么人们似乎认为PDF是一种图像格式?这显然不是。 – Nyerguds 2018-01-08 15:29:20

回答

0

我不认为可以将数组复制到位图数据。步幅可能不同,比特深度可能不同,字节顺序可能不同等等。 Lajja Thaker发布了其中一种方法。 另请注意,在Windows XP下不支持一些彩色tiff。

0

Bitmiracle不是图书馆,it is a name of a software company,它是libtiff你试图使用什么?也许你可以联系Bitmiracle寻求你正在从事的任务的支持。

您不能通过从PDF中提取二进制数据并将其转储到位图对象中来从PDF创建tiff图像。这就像试图通过挤压苹果来制作橙汁。

如果您想将PDF文件转换为TIFF图像,我建议您使用允许您呈现PDF文件的库。搜索PDF to Image conversion with C#了解更多详情。

如果您只是想从PDF文件中提取已经压缩为TIFF的图像,那么您确实可以将extract the binary data保存到其他地方。