【问题标题】:Trying to create Tif from PDF. Getting bad image尝试从 PDF 创建 Tif。形象变差
【发布时间】:2012-07-23 20:42:29
【问题描述】:

我正在尝试使用 Itextsharp 和 Bitmiracle 从 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;
}

请帮助我解决代码中的问题或建议我进行更改。

提前感谢您的帮助。

【问题讨论】:

  • 为什么人们似乎认为 PDF 是一种图像格式?显然不是。

标签: c# pdf image-processing itextsharp tiff


【解决方案1】:

您可以参考以下链接。

http://www.codeproject.com/Articles/37458/PDF-Viewer-Control-Without-Acrobat-Reader-Installe

还有一个选项可以将 pdf 转换为 tiff 文件或其他文件。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      Bitmiracle 不是一个库,it is a name of a software company,它是你想要使用的 libtiff 吗?也许您可以联系 Bitmiracle 以获取有关您正在处理的任务的支持。

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-17
        • 1970-01-01
        • 2022-06-24
        • 1970-01-01
        • 1970-01-01
        • 2012-03-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多