Browse Source

Added ImageUtils.GetPDFThumbnail

frogsoftware 1 year ago
parent
commit
8c08b3c92e
1 changed files with 9 additions and 0 deletions
  1. 9 0
      inabox.wpf/ImageUtils.cs

+ 9 - 0
inabox.wpf/ImageUtils.cs

@@ -803,6 +803,15 @@ namespace InABox.WPF
             return null;
         }
 
+        public static byte[] GetPDFThumbnail(byte[] pdfData, int width, int height)
+        {
+            PdfLoadedDocument loadeddoc = new PdfLoadedDocument(pdfData);
+            Bitmap image = loadeddoc.ExportAsImage(0, new SizeF(width, height), true);
+            MemoryStream stream = new MemoryStream();
+            image.Save(stream, ImageFormat.Jpeg);
+            return stream.ToArray();
+        }
+
         public static List<byte[]> RenderPDFToImages(byte[] pdfData, ImageEncoding encoding = ImageEncoding.JPEG)
         {
             var rendered = new List<byte[]>();