using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using DevExtreme.AspNet.Mvc.FileManagement; using PdfiumViewer; namespace PdfThumbnailExtractor { public class PdfThumbnailService { public static string GenerateThumbnail(FileSystemLoadFile file) { // Ensure the uploaded file is a PDF if (!file.Name.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException("Only PDF files are supported."); } // Load the PDF file using (var pdfStream = new MemoryStream(file.Content)) using (var pdfDocument = PdfDocument.Load(pdfStream)) { // Render the first page as an image var image = pdfDocument.Render(0, 200, 200, true); // Save the thumbnail to a temporary file var thumbnailPath = Path.Combine(Path.GetTempPath(), $"{Path.GetFileNameWithoutExtension(file.Name)}_thumbnail.png"); image.Save(thumbnailPath, ImageFormat.Png); return thumbnailPath; } } } } /* using DevExpress.Pdf; using DevExpress.Drawing; using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) { processor.LoadDocument("uploaded.pdf"); DXBitmap bitmap = processor.CreateBitmap(0); // First page bitmap.Save("thumbnail.png"); } */