使用之前堆栈溢出问题中的代码:
System.Drawing.Bitmap image;
ShellFile f = ShellFile.FromFilePath(fileLocation);
image = f.Thumbnail.ExtraLargeBitmap;
image.Save(tempfile, ImageFormat.Png);
我正在尝试使用 window API 来获取 PDF 的缩略图
我相信这会生成一个类似于 PDF 文档第一页的图像文件。
然而实际情况是,它看起来并非如此,而只是看起来像 PDF 图标。
在实际按预期工作之前,我是否缺少任何需要的东西?
PDF 文件与 adobe reader 正确关联。
在 Windows 资源管理器中浏览目录时我DO查看与文档相关的缩略图。
我应该注意到,在处理 Excel 和 Word 文档时,代码实际上确实正确地提取了缩略图。
编辑(参考文献):
- C# 通过 windows api 从文件中获取缩略图 https://stackoverflow.com/questions/1439719/c-sharp-get-thumbnail-from-file-via-windows-api
- 获取任何文件的缩略图,而不仅仅是 Windows XP/Vista 上的图像文件 https://stackoverflow.com/questions/11888025/get-thumbnail-of-any-file-not-only-image-files-on-windows-xp-vista
- Windows API 代码包缩略图提供 pdf 的预览缩略图,但不提供 Word 或 Excel https://stackoverflow.com/questions/6918586/windows-api-code-pack-thumbnail-gives-preview-thumb-of-pdf-but-not-word-or-excel
您需要指定您需要缩略图,而不是图标(默认)。
将您的代码更改为:
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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)