-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomOperationLogger.cs
68 lines (67 loc) · 2.93 KB
/
CustomOperationLogger.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
64
65
66
67
68
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.Web.ClientControls;
using DevExpress.XtraReports.Web.WebDocumentViewer;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
namespace PowerPointExport
{
public class CustomOperationLogger : WebDocumentViewerOperationLogger
{
public override ExportedDocument ExportDocumentStarting(string documentId, string asyncExportOperationId, string format, ExportOptions options, PrintingSystemBase printingSystem, Func<ExportedDocument> doExportSynchronously)
{
if (format == "powerPoint")
{
return new ExportedDocument(ExportToPowerPoint(printingSystem, documentId), @"application/vnd.ms-powerpoint", printingSystem.Document.Name + ".ppt");
}
return base.ExportDocumentStarting(documentId, asyncExportOperationId, format, options, printingSystem, doExportSynchronously);
}
byte[] ExportToPowerPoint(PrintingSystemBase printingSystem, string documentId)
{
// To the temp folder (for demo purposes)
var tempFolder = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/PowerPoint/");
if (!Directory.Exists(tempFolder))
{
Directory.CreateDirectory(tempFolder);
}
// image export options
ImageExportOptions exportOptions = new ImageExportOptions
{
ExportMode = ImageExportMode.SingleFilePageByPage,
Format = ImageFormat.Png,
PageBorderColor = Color.White,
Resolution = 600
};
// PowerPoint Presentation
Size size = CalculateSize(printingSystem);
Presentation p = new Presentation(size);
// go through each page
for (int i = 0; i < printingSystem.Pages.Count; i++)
{
// export image
var file = string.Format(@"{0}\{1}_{2}.png", tempFolder, documentId, i);
exportOptions.PageRange = (i + 1).ToString();
printingSystem.ExportToImage(file, exportOptions);
// add the image to the presentation
p.AddPage(file);
// clean up!
File.Delete(file);
}
// save presentation
string resultFile = string.Format(@"{0}\{1}.ppt", tempFolder, documentId);
p.SaveAs(resultFile);
byte[] document = File.ReadAllBytes(resultFile);
File.Delete(resultFile);
return document;
}
Size CalculateSize(PrintingSystemBase printingSystem)
{
SizeF size = printingSystem.Pages[0].PageSize.ToSize();
return GraphicsUnitConverter.Convert(size, GraphicsUnit.Document.ToDpi(), GraphicsUnit.Point.ToDpi()).ToSize();
}
}
}