Example #1
0
        public static string PDFToBMP(string pdfFilePath, string bmpFilePath)
        {
            var stream     = new FileStream(pdfFilePath, FileMode.Open);
            var pdfConvert = new Aspose.Pdf.Facades.PdfConverter();
            var pdfDoc     = new Aspose.Pdf.Document(stream);

            pdfConvert.BindPdf(pdfDoc);
            pdfConvert.DoConvert();
            pdfConvert.GetNextImage(bmpFilePath, new Aspose.Pdf.PageSize(200, 150), System.Drawing.Imaging.ImageFormat.Bmp);
            pdfConvert.Close();
            pdfConvert.Dispose();
            stream.Flush();
            stream.Close();
            return(bmpFilePath);
        }
        public MemoryStream ConvertPDFToImage(string filepath, int page)
        {
            var converter = new Aspose.Pdf.Facades.PdfConverter();

            converter.BindPdf(filepath);
            converter.StartPage  = page;
            converter.EndPage    = page;
            converter.Resolution = new Aspose.Pdf.Devices.Resolution(300);
            converter.DoConvert();

            MemoryStream imageStream = new MemoryStream();

            while (converter.HasNextImage())
            {
                converter.GetNextImage(imageStream, System.Drawing.Imaging.ImageFormat.Png);
                imageStream.Position = 0;
            }
            return(imageStream);
        }
Example #3
0
        /// <summary>
        /// 生成缩略图,只生成第一张页面的缩略图
        /// </summary>
        /// <param name="fileBuffer">文件的字节数组</param>
        /// <param name="fileType">文件类型,目前支持:Word、Excel、PDF</param>
        public static byte[] ConvertToSnap(byte[] fileBuffer, string fileType)
        {
            var snapStream = new MemoryStream();

            if (fileType == "xls" || fileType == "xlsx")
            {
                var book       = new Aspose.Cells.Workbook(new MemoryStream(fileBuffer));
                var sheet      = book.Worksheets[0];
                var imgOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions
                {
                    OnePagePerSheet      = true,
                    VerticalResolution   = 400,
                    HorizontalResolution = 300,
                    ImageFormat          = System.Drawing.Imaging.ImageFormat.Jpeg
                };
                var sr = new Aspose.Cells.Rendering.SheetRender(sheet, imgOptions);
                sr.ToImage(0, snapStream);
            }
            else if (fileType == "doc" || fileType == "docx")
            {
                var doc        = new Aspose.Words.Document(new MemoryStream(fileBuffer));
                var imgOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg)
                {
                    Resolution = 400,
                };
                doc.Save(snapStream, imgOptions);
            }
            else if (fileType == "pdf")
            {
                var converter = new Aspose.Pdf.Facades.PdfConverter();
                converter.BindPdf(new Aspose.Pdf.Document(new MemoryStream(fileBuffer)));
                converter.DoConvert();
                converter.GetNextImage(snapStream, new Aspose.Pdf.PageSize(200, 150), System.Drawing.Imaging.ImageFormat.Jpeg);
            }

            var result = snapStream.ToArray();

            snapStream.Close();
            return(result);
        }