PDFHelper.cs
2.33 KB
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
69
70
71
72
73
74
75
76
77
78
79
using Aspose.Cells;
using Spire.Presentation;
using System;
namespace NCC.Common.Helper
{
public class PDFHelper
{
/// <summary>
/// Aspose组件Excel转成pdf文件
/// </summary>
/// <param name="fileName">word文件路径</param>
public static void AsposeExcelToPDF(string fileName)
{
try
{
var pdfSavePath = fileName.Substring(0, fileName.LastIndexOf(".")) + ".pdf";
if (!FileHelper.IsExistFile(pdfSavePath))
{
Workbook excel = new Workbook(fileName);
if (excel != null)
{
excel.Save(pdfSavePath, SaveFormat.Pdf);
}
}
}
catch (Exception ex)
{
throw ;
}
}
/// <summary>
/// Aspose组件word转成pdf文件
/// </summary>
/// <param name="fileName">word文件路径</param>
public static void AsposeWordToPDF(string fileName)
{
try
{
var pdfSavePath = fileName.Substring(0, fileName.LastIndexOf(".")) + ".pdf";
if (!FileHelper.IsExistFile(pdfSavePath))
{
var document = new Aspose.Words.Document(fileName);
if (document != null)
{
document.Save(pdfSavePath, Aspose.Words.SaveFormat.Pdf);
}
}
}
catch (Exception ex)
{
throw ;
}
}
/// <summary>
/// PPT转换PDF
/// </summary>
/// <param name="fileName">文件名称</param>
public static void PPTToPDF(string fileName)
{
try
{
if (!FileHelper.IsExistFile(fileName.Substring(0, fileName.LastIndexOf(".")) + ".pdf"))
{
Presentation presentation = new Presentation();
presentation.LoadFromFile(fileName);
presentation.SaveToFile(fileName.Substring(0, fileName.LastIndexOf(".")) + ".pdf", FileFormat.PDF);
}
}
catch (Exception ex)
{
throw;
}
}
}
}