【问题标题】:Windows API Code Pack - ShellFile not generating PDF bitmapWindows API 代码包 - ShellFile 不生成 PDF 位图
【发布时间】:2013-08-18 05:05:52
【问题描述】:

使用之前堆栈溢出问题中的代码:

System.Drawing.Bitmap image;
ShellFile f = ShellFile.FromFilePath(fileLocation);
image = f.Thumbnail.ExtraLargeBitmap;
image.Save(tempfile, ImageFormat.Png);

我正在尝试使用窗口 API 来获取 PDF 的缩略图

我相信这会生成一个类似于 PDF 文档第一页的图像文件。

但现实情况是,它看起来不像,只是看起来像 PDF 图标。

在真正按预期工作之前,我是否缺少任何需要的东西?

PDF 文件与 adobe reader 正确关联。

在 Windows 资源管理器中浏览目录时,我确实会看到与文档关联的缩略图。

我应该注意到,在处理 Excel 和 Word 文档时,代码实际上可以正确提取缩略图。

编辑(参考):

【问题讨论】:

  • 在 Windows 2008R2 上出现同样的问题。如果没有安装 Adob​​e Reader,我只会得到一个空白文档缩略图。安装 Adob​​e Reader 并重新启动后,我得到指示文件类型的 Adob​​e PDF 缩略图。然而,在我的开发者机器上,它是 Windows 7,它对我来说很好,并给了我正确的缩略图。
  • 您自己找到解决方案了吗?我面临同样的问题,但与数据格式无关。如果你能分享你的代码就好了

标签: c# pdf thumbnails windows-api-code-pack


【解决方案1】:

您需要指定您想要缩略图,而不是图标(默认)。 将您的代码更改为:

System.Drawing.Bitmap image;
ShellFile f = ShellFile.FromFilePath(fileLocation);

//force the actual thumbnail, not the icon
f.Thumbnail.FormatOption = ShellThumbnailFormatOption.ThumbnailOnly;

image = f.Thumbnail.ExtraLargeBitmap;
image.Save(tempfile, ImageFormat.Png);

【讨论】:

    【解决方案2】:

    问题是因为您没有选择要从中创建缩略图的活动框架。

    我无法在我当前的机器上验证它,因为我没有 Windows API,但它为您提供标准 PDF 缩略图,因为在您的代码中您没有指定用于缩略图的页面。

    尝试做这样的事情:

            Image image = new Image();
            //Load image here
            int frameindex = 1; // Page number you want to use for thumbnail
            Guid guide = image.FrameDimensionsList[0];
            FrameDimension fDimension = new FrameDimension(guide);
            image.SelectActiveFrame(fDimension, frameindex);
            //Then go on to extract your thumbnail
    

    【讨论】:

    • 谢谢!我会试试这个。尽快
    • 嗯...遗憾的是这似乎不起作用。感谢您的贡献。
    【解决方案3】:

    我无法让 ExtraLargeBitmap 用于 PDF 文件,但所有其他尺寸(大、中和小)都可以正常工作。

    Dim MyShellFile As ShellFile = ShellFile.FromFilePath(fi.FullName)
    Dim MyThumbNail As Image
    MyShellFile.Thumbnail.FormatOption = ShellThumbnailFormatOption.ThumbnailOnly
    MyThumbNail = MyShellFile.Thumbnail.LargeBitmap
    Me.PictureBox2.Image = MyThumbNail
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-28
      • 1970-01-01
      • 2012-05-02
      • 2023-04-04
      • 1970-01-01
      相关资源
      最近更新 更多