Windows API Code Code - ShellFile Does Not Generate PDF Bitmap

Using code from previous questions:

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

I am trying to use the window API to get a PDF thumbnail

I am convinced that this creates an image file that resembles the first page of a PDF document.

The reality, however, is that it does NOT look that way and looks just like a PDF icon.

Is there something that I am missing that is required before it really works as intended?

PDF files are correctly associated with Adobe Reader.

When viewing directories in Windows Explorer, I see thumbnails associated with documents.

I should notice that the code really correctly extracts thumbnails when working with Excel and Word documents.

EDIT (links):

+4
source share
3 answers

You need to specify that you want a thumbnail, not an icon (default). Change the code as follows:

 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
source

The problem is that you did not select the active frame from which you will create the thumbnail.

I can’t check this on my current computer because I don’t have the Windows API on it, but it gives you the standard PDF thumbnail, because in your code you did not specify which page to use for thumbnail.

Try to do 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 
+1
source

I was not able to get ExtraLargeBitmap to work for PDF files, but all other sizes (Large, Medium and Small) worked fine.

 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 
0
source

Source: https://habr.com/ru/post/1497331/


All Articles