-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageExporterHelper.cs
63 lines (58 loc) · 2.18 KB
/
ImageExporterHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using DevExpress.Office.Utils;
using DevExpress.Pdf;
using DevExpress.Spreadsheet;
using DevExpress.XtraPrinting;
using DevExpress.XtraPrintingLinks;
using DevExpress.XtraRichEdit;
using System;
using System.Drawing;
using System.IO;
using System.Linq;
namespace FilesPreviewGenerator
{
public static class ImageExporterHelper
{
public static Image GenerateImageFromExcel(string fileName)
{
using (Workbook excelDocumentAPI = new Workbook())
{
excelDocumentAPI.LoadDocument(fileName);
var worksheet = excelDocumentAPI.Worksheets.ActiveWorksheet;
var printableCellRange = worksheet.GetPrintableRange();
OfficeImage docImage = printableCellRange.ExportToImage();
return docImage.NativeImage;
}
}
public static Bitmap GenerateImageFromPDF(string fileName, int largestEdgeLength)
{
using (PdfDocumentProcessor pdfDocumentAPI = new PdfDocumentProcessor())
{
pdfDocumentAPI.LoadDocument(fileName);
return pdfDocumentAPI.CreateBitmap(1, largestEdgeLength);
}
}
public static Bitmap GenerateImageFromWord(string fileName)
{
using (RichEditDocumentServer wordDocumentAPI = new RichEditDocumentServer())
{
wordDocumentAPI.LoadDocument(fileName);
return ExportToImage(wordDocumentAPI);
}
}
private static Bitmap ExportToImage(IBasePrintable component)
{
PrintableComponentLinkBase pLink = new PrintableComponentLinkBase(new PrintingSystemBase());
pLink.Component = component;
pLink.CreateDocument(true);
MemoryStream mStream = new MemoryStream();
ImageExportOptions options = new ImageExportOptions();
options.ExportMode = ImageExportMode.SingleFilePageByPage;
options.PageRange = "1";
pLink.ExportToImage(mStream, options);
mStream.Position = 0;
Bitmap bm = new Bitmap(mStream);
mStream.Close();
return bm;
}
}
}