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); }
private static void test2() { // load the PDF in PdfConverter using (var converter = new Aspose.Pdf.Facades.PdfConverter()) { converter.BindPdf("template.pdf"); // initiate conversion converter.DoConvert(); // create TiffSettings & set compression type var settings = new Aspose.Pdf.Devices.TiffSettings() { Compression = Aspose.Pdf.Devices.CompressionType.None, }; // save PDF as TIFF converter.SaveAsTIFF("output.tiff", settings); } }
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); }
/// <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); }
private static string SaveAsTiff(string inputFile, string outputFolder) { try { if (!File.Exists(inputFile)) { throw new FileNotFoundException($"Die Datei {inputFile} konnte nicht gefunden werden"); } //create var pdfConverter = new Aspose.Pdf.Facades.PdfConverter(); // create Resolution object with 300 as an argument var resolution = new Resolution(240); // specify the resolution value for PdfConverter object - default is 150 pdfConverter.Resolution = resolution; // bind the source PDF file pdfConverter.BindPdf(inputFile); // start the conversion process pdfConverter.DoConvert(); //create TiffSettings object, set Compression and ColorDepth var tiffSettings = new TiffSettings { Compression = CompressionType.None }; var guid = Guid.NewGuid().ToString(); var filepath = Path.Combine(outputFolder, $"{Path.GetFileNameWithoutExtension(guid)}.tiff"); pdfConverter.SaveAsTIFF(filepath, tiffSettings); pdfConverter.Close(); return(filepath); } catch (Exception e) { Console.WriteLine(e); throw; } }