Making PDF thumbnails with ImageSharp
# help-with-other
s
Anyone know of a PDF provider for ImageSharp, so I could do like /media/xyz/document.pdf?format=jpeg?
r
That's not really what imagesharp is for, since pdfs are a document type, not an image. To create an image from a pdf it would need to be able to read that data, and pdfs are complicated. You'll probably want to use a pdf reader to do this instead, such as PdfLibCore which has image generation as its sample usage: https://github.com/jbaarssen/PdfLibCore
s
Thanks - what I want is to be able to create a thumbnail of the first page in the pdf. I've actually been able to create a new decoder for ImageSharp that does this. Now I just need to get Umbraco working with it πŸ™‚
r
Nice! Please share the code/snippet once you've got it working, I'd love to see it
s
will do πŸ™‚
d
I think @AaronSadlerUK has worked on a package that does that https://github.com/Moriyama-Umbraco/Moriyama.PreviewPDF
s
c
We write our own component that creates PDF thumbnails, but we opted to create them when the PDF is uploaded in the media section, so it’s a one of conversion. We used PDFPIG for the image generation which seems to work well.
j
Thanks so much @skttl for this! I've been all over the place trying to sort x-plat PDF rendering and ended up overengineering something wild. This has set me in the right direction. For anyone wanting to solve this problem without an ImageSharp dependency I can recommend https://github.com/sungaila/PDFtoImage which also uses PDFium for rendering but SkiaSharp for processing.
35 Views