简体   繁体   English

Windows API代码包 - ShellFile不生成PDF位图

[英]Windows API Code Pack - ShellFile not generating PDF bitmap

Using the code from previous stack overflow questions: 使用以前堆栈溢出问题中的代码:

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

I am trying to use window API to get the thumbnail of a PDF 我正在尝试使用窗口API来获取PDF的缩略图

I am led to believe that this generates an image file that resembles the first page of the PDF document. 我被认为这会生成一个类似于PDF文档第一页的图像文件。

The reality however is that it does NOT look like that, and merely looks like the PDF icon. 但事实是,它看起来并不像那样,只是看起来像PDF图标。

Is there anything that I'm missing that is required before this actually works as intended? 在实际按预期工作之前,是否有任何我需要的东西?

PDF files are correctly associated with adobe reader. PDF文件与adobe reader正确关联。

When browsing directories in windows explorer I DO see thumbnails associated with the documents. 当在Windows Explorer中浏览目录, 看到与文件相关的缩略图。

I should note that the code DOES in fact correctly extract thumbnails when dealing with Excel and Word documents. 我应该注意,代码实际上在处理Excel和Word文档时正确提取缩略图。

EDIT (references): 编辑(参考):

You need to specify that you want the thumbnail, not the icon (the default). 您需要指定您想要缩略图,而不是图标(默认)。 Change your code into this: 将您的代码更改为:

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);

The problem is because you have not selected the active frame that you will create the thumbnail from. 问题是因为您没有选择要从中创建缩略图的活动框架。

I cannot verify it on my current machine, because I don't have the Windows API on it, but it's giving you the standard PDF thumbnail because in your code you have't specified which page to use for the thumbnail. 我无法在当前的机器上验证它,因为我没有Windows API,但是它给你标准的PDF缩略图,因为在你的代码中你没有指定用于缩略图的页面。

Try doing something like this: 尝试做这样的事情:

        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

I was not able to get ExtraLargeBitmap to work for PDF files but all other sizes (Large, Medium, and Small) worked fine. 我无法让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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM