Create best resolution PDF thumbnail

I have a listbox containing the titles of PDF articles, and I want to display the thumbnail of each. This is relatively easy to do, but the results are faint and blurry, even on a Retina display. This is despite the fact that I’m getting the vector graphic of the PDF, and Hi-DPI is turned on. Other apps I have that do this display a much crisper PDF image, so I know it’s possible. Any ideas on how to improve this code?

      dim p as picture = f.OpenAsVectorPicture //Type = image = 0, i.e. An Image for use with HiDPI displays.

//calculate scaling factor for a 41 * 56 thumbnail
dim factorx, factory as double
factorx = 41/p.width
factory = 56/p.height

//draw opaque white background
g.ForeColor = RGB(255, 255, 255)
g.FillRect 30, 4, p.width * factorx, p.height * factory

//draw PDF first page vector graphic in the listbox row, x = 30, y = 4
g.DrawPicture p, 30, 4, p.width * factorx, p.height * factory, 0, 0, p.Width, p.Height

Do you use MBS Xojo Plugins?
The PDFKit or DynaPDF classes could give you the picture easily.

e.g. open page with PDFDocumentMBS class, than get PDFPageMBS object of the page and call Render method.

Thanks for the suggestion, I’ll see if those approaches are better. But getting the vector image is not the problem. The quality of the display is. I’ll post if using a PDF class improves things.

Christian, when I run your example “Render PDFPage”, the white portions of the PDF page are rendered in black.

There’s a couple of things I can suggest, I suspect it has something to do with drawing the image down and reduction techniques.

  1. On macOS you can get QuickLook to return you a preview at a scaled size.
  2. There’s declares on this forum for scaling images, or rather adjusting your target context/graphics class to change the interpolation mechanism used, which can result in ‘sharper’ images. I find for scaling images down, I tend to turn this off if I want it really sharp.
  3. Run a sharpen algorithm on the reduced size or use Unsharp Mask.

[quote=365443:@Jonathan Ashwell] factorx = 41/p.width
factory = 56/p.height[/quote]
Isn’t this giving you negative values ?

Well, not sure what PDF you have. You may need to set background color to white.

@Sam Rowlands Thanks, I’ll check these out.

@Emile Schwarz How can the division of two positive numbers yield a negative?

@Christian Schmitz Many PDFs of journal articles. Setting the image.background to white doesn’t have any affect. I can send you an example if you like.

Send example file to test, please.