Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Education
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
Education
Commits
b7bbaf2d
Commit
b7bbaf2d
authored
Sep 30, 2020
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
505a666a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
19 deletions
+61
-19
IImageHelper.cs
Edu.Common/Plugin/IImageHelper.cs
+59
-17
CourseController.cs
Edu.WebApi/Controllers/Course/CourseController.cs
+2
-2
No files found.
Edu.Common/Plugin/IImageHelper.cs
View file @
b7bbaf2d
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using
System.Drawing
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.Drawing.Imaging
;
using
System.IO
;
using
System.IO
;
using
System.Net
;
namespace
Edu.Common.Plugin
namespace
Edu.Common.Plugin
{
{
...
@@ -11,12 +12,15 @@ namespace Edu.Common.Plugin
...
@@ -11,12 +12,15 @@ namespace Edu.Common.Plugin
/// </summary>
/// </summary>
public
class
ImageHelper
public
class
ImageHelper
{
{
/// <summary>
/// 生成图片
/**
/// </summary>
* 生成图片
/// <param name="sourceFile">源文件地址</param>
* string targetFile = @"F:/Test/temp/";
/// <param name="targetFile">目标文件路径</param>
* ImageHelper.CreateImage("F:/Test/1.docx", targetFile);
/// <returns></returns>
* ImageHelper.CreateImage("F:/Test/2.pdf", targetFile);
* ImageHelper.CreateImage("F:/Test/3.ppt", targetFile);
* ImageHelper.CreateImage("F:/Test/4.xls", targetFile);
*/
public
static
List
<
string
>
CreateImage
(
string
sourceFile
,
string
targetFile
)
public
static
List
<
string
>
CreateImage
(
string
sourceFile
,
string
targetFile
)
{
{
IImageHelper
imageHelper
=
null
;
IImageHelper
imageHelper
=
null
;
...
@@ -48,6 +52,38 @@ namespace Edu.Common.Plugin
...
@@ -48,6 +52,38 @@ namespace Edu.Common.Plugin
}
}
return
imageHelper
.
CreateImage
(
sourceFile
,
targetFile
);
return
imageHelper
.
CreateImage
(
sourceFile
,
targetFile
);
}
}
/// <summary>
/// 生成图片
/// </summary>
/// <param name="url"></param>
public
static
void
CreateImage
(
string
url
)
{
string
tempPath
=
Common
.
Config
.
GetFileUrl
(
url
);
string
path
=
Environment
.
CurrentDirectory
+
tempPath
;
//下载到的地址+文件名
HttpWebRequest
request
=
WebRequest
.
Create
(
url
)
as
HttpWebRequest
;
//发送请求并获取相应回应数据
HttpWebResponse
response
=
request
.
GetResponse
()
as
HttpWebResponse
;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
Stream
responseStream
=
response
.
GetResponseStream
();
string
newFilePath
=
path
.
Substring
(
0
,
path
.
LastIndexOf
(
"/"
));
if
(!
System
.
IO
.
Directory
.
Exists
(
newFilePath
))
//如果不存在就创建file文件夹
{
System
.
IO
.
Directory
.
CreateDirectory
(
newFilePath
);
}
//创建本地文件写入流
Stream
stream
=
new
FileStream
(
path
,
FileMode
.
Create
);
byte
[]
bArr
=
new
byte
[
1024
];
int
size
=
responseStream
.
Read
(
bArr
,
0
,
(
int
)
bArr
.
Length
);
while
(
size
>
0
)
{
stream
.
Write
(
bArr
,
0
,
size
);
size
=
responseStream
.
Read
(
bArr
,
0
,
(
int
)
bArr
.
Length
);
}
stream
.
Close
();
responseStream
.
Close
();
}
}
}
/// <summary>
/// <summary>
...
@@ -60,8 +96,9 @@ namespace Edu.Common.Plugin
...
@@ -60,8 +96,9 @@ namespace Edu.Common.Plugin
/// </summary>
/// </summary>
/// <param name="sourceFile">源文件地址</param>
/// <param name="sourceFile">源文件地址</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="prefix">生成文件前缀</param>
/// <returns></returns>
/// <returns></returns>
List
<
string
>
CreateImage
(
string
sourceFile
,
string
targetFile
);
List
<
string
>
CreateImage
(
string
sourceFile
,
string
targetFile
,
string
prefix
=
""
);
}
}
/// <summary>
/// <summary>
...
@@ -74,8 +111,9 @@ namespace Edu.Common.Plugin
...
@@ -74,8 +111,9 @@ namespace Edu.Common.Plugin
/// </summary>
/// </summary>
/// <param name="sourceFile">源文件地址</param>
/// <param name="sourceFile">源文件地址</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="prefix">生成文件前缀</param>
/// <returns></returns>
/// <returns></returns>
public
List
<
string
>
CreateImage
(
string
sourceFile
,
string
targetFile
)
public
List
<
string
>
CreateImage
(
string
sourceFile
,
string
targetFile
,
string
prefix
=
""
)
{
{
List
<
string
>
list
=
new
List
<
string
>();
List
<
string
>
list
=
new
List
<
string
>();
try
try
...
@@ -84,7 +122,7 @@ namespace Edu.Common.Plugin
...
@@ -84,7 +122,7 @@ namespace Edu.Common.Plugin
xls
.
LoadFromFile
(
sourceFile
,
Spire
.
Xls
.
ExcelVersion
.
Version97to2003
);
xls
.
LoadFromFile
(
sourceFile
,
Spire
.
Xls
.
ExcelVersion
.
Version97to2003
);
string
tempPdf
=
targetFile
+
"xls_temp_"
+
DateTime
.
Now
.
Ticks
+
".pdf"
;
string
tempPdf
=
targetFile
+
"xls_temp_"
+
DateTime
.
Now
.
Ticks
+
".pdf"
;
xls
.
SaveToFile
(
tempPdf
,
Spire
.
Xls
.
FileFormat
.
PDF
);
xls
.
SaveToFile
(
tempPdf
,
Spire
.
Xls
.
FileFormat
.
PDF
);
list
=
new
PdfToImage
().
CreateImage
(
tempPdf
,
targetFile
);
list
=
new
PdfToImage
().
CreateImage
(
tempPdf
,
targetFile
,
prefix
:
"xls_"
);
File
.
Delete
(
tempPdf
);
File
.
Delete
(
tempPdf
);
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
...
@@ -105,8 +143,9 @@ namespace Edu.Common.Plugin
...
@@ -105,8 +143,9 @@ namespace Edu.Common.Plugin
/// </summary>
/// </summary>
/// <param name="sourceFile">源文件地址</param>
/// <param name="sourceFile">源文件地址</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="prefix">生成文件前缀</param>
/// <returns></returns>
/// <returns></returns>
public
List
<
string
>
CreateImage
(
string
sourceFile
,
string
targetFile
)
public
List
<
string
>
CreateImage
(
string
sourceFile
,
string
targetFile
,
string
prefix
=
""
)
{
{
List
<
string
>
list
=
new
List
<
string
>();
List
<
string
>
list
=
new
List
<
string
>();
try
try
...
@@ -143,23 +182,24 @@ namespace Edu.Common.Plugin
...
@@ -143,23 +182,24 @@ namespace Edu.Common.Plugin
/// 生成图片地址
/// 生成图片地址
/// </summary>
/// </summary>
/// <param name="sourceFile">源文件地址</param>
/// <param name="sourceFile">源文件地址</param>
/// <param name="targetFile">目标文件路径</param>>
/// <param name="targetFile">目标文件路径</param>
/// <param name="prefix">生成文件前缀</param>
/// <returns></returns>
/// <returns></returns>
public
List
<
string
>
CreateImage
(
string
sourceFile
,
string
targetFile
)
public
List
<
string
>
CreateImage
(
string
sourceFile
,
string
targetFile
,
string
prefix
=
""
)
{
{
List
<
string
>
list
=
new
List
<
string
>();
List
<
string
>
list
=
new
List
<
string
>();
string
license
=
AppContext
.
BaseDirectory
+
@"ExtPlug\Aspose.Total.lic"
;
string
license
=
AppContext
.
BaseDirectory
+
@"ExtPlug\Aspose.Total.lic"
;
try
try
{
{
//加载证书
Aspose
.
Pdf
.
License
license2
=
new
Aspose
.
Pdf
.
License
();
Aspose
.
Pdf
.
License
license2
=
new
Aspose
.
Pdf
.
License
();
license2
.
SetLicense
(
license
);
license2
.
SetLicense
(
license
);
Aspose
.
Pdf
.
Document
document
=
new
Aspose
.
Pdf
.
Document
(
sourceFile
);
Aspose
.
Pdf
.
Document
document
=
new
Aspose
.
Pdf
.
Document
(
sourceFile
);
//默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
var
device
=
new
Aspose
.
Pdf
.
Devices
.
PngDevice
();
var
device
=
new
Aspose
.
Pdf
.
Devices
.
PngDevice
();
//遍历每一页转为PNG
//遍历每一页转为PNG
for
(
var
i
=
1
;
i
<=
document
.
Pages
.
Count
;
i
++)
for
(
var
i
=
1
;
i
<=
document
.
Pages
.
Count
;
i
++)
{
{
string
filePathOutPut
=
targetFile
+
"pdf_"
+
i
+
"_"
+
DateTime
.
Now
.
ToString
(
"yyyyMMddHHmmssfff"
)
+
".png"
;
string
filePathOutPut
=
targetFile
+
(!
string
.
IsNullOrWhiteSpace
(
prefix
)
?
prefix
:
"pdf_"
)
+
i
+
"_"
+
DateTime
.
Now
.
ToString
(
"yyyyMMddHHmmssfff"
)
+
".png"
;
FileStream
fs
=
new
FileStream
(
filePathOutPut
,
FileMode
.
OpenOrCreate
);
FileStream
fs
=
new
FileStream
(
filePathOutPut
,
FileMode
.
OpenOrCreate
);
try
try
{
{
...
@@ -192,8 +232,9 @@ namespace Edu.Common.Plugin
...
@@ -192,8 +232,9 @@ namespace Edu.Common.Plugin
/// </summary>
/// </summary>
/// <param name="sourceFile">源文件地址</param>
/// <param name="sourceFile">源文件地址</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="targetFile">目标文件路径</param>
/// <param name="prefix">生成文件前缀</param>
/// <returns></returns>
/// <returns></returns>
public
List
<
string
>
CreateImage
(
string
sourceFile
,
string
targetFile
)
public
List
<
string
>
CreateImage
(
string
sourceFile
,
string
targetFile
,
string
prefix
=
""
)
{
{
List
<
string
>
list
=
new
List
<
string
>();
List
<
string
>
list
=
new
List
<
string
>();
try
try
...
@@ -204,8 +245,9 @@ namespace Edu.Common.Plugin
...
@@ -204,8 +245,9 @@ namespace Edu.Common.Plugin
for
(
int
i
=
0
;
i
<
ppt
.
Slides
.
Count
;
i
++)
for
(
int
i
=
0
;
i
<
ppt
.
Slides
.
Count
;
i
++)
{
{
string
newFilePath
=
string
.
Format
(
targetFile
+
"ppt_"
+
i
+
"_"
+
@"{0}.png"
,
DateTime
.
Now
.
ToString
(
"yyyyMMddHHmmssfff"
));
string
newFilePath
=
string
.
Format
(
targetFile
+
"ppt_"
+
i
+
"_"
+
@"{0}.png"
,
DateTime
.
Now
.
ToString
(
"yyyyMMddHHmmssfff"
));
Image
image
=
ppt
.
Slides
[
i
].
SaveAsImage
();
//读取emf格式图片
//保存为PNG图片
image
.
Save
(
newFilePath
,
ImageFormat
.
Png
);
//把emf格式的图片转换成Png格式
Image
image
=
ppt
.
Slides
[
i
].
SaveAsImage
();
image
.
Save
(
newFilePath
,
ImageFormat
.
Png
);
list
.
Add
(
newFilePath
);
list
.
Add
(
newFilePath
);
}
}
ppt
.
Dispose
();
ppt
.
Dispose
();
...
...
Edu.WebApi/Controllers/Course/CourseController.cs
View file @
b7bbaf2d
...
@@ -82,11 +82,11 @@ namespace Edu.WebApi.Controllers.Course
...
@@ -82,11 +82,11 @@ namespace Edu.WebApi.Controllers.Course
var
cateIds
=
base
.
ParmJObj
.
GetStringValue
(
"cateIds"
);
var
cateIds
=
base
.
ParmJObj
.
GetStringValue
(
"cateIds"
);
var
list
=
categoryModule
.
GetChildCategoryStringModule
(
cateIds
);
var
list
=
categoryModule
.
GetChildCategoryStringModule
(
cateIds
);
string
targetFile
=
@"F:/Test/temp/"
;
//
string targetFile = @"F:/Test/temp/";
//ImageHelper.CreateImage("F:/Test/1.docx", targetFile);
//ImageHelper.CreateImage("F:/Test/1.docx", targetFile);
//ImageHelper.CreateImage("F:/Test/2.pdf", targetFile);
//ImageHelper.CreateImage("F:/Test/2.pdf", targetFile);
//ImageHelper.CreateImage("F:/Test/3.ppt", targetFile);
//ImageHelper.CreateImage("F:/Test/3.ppt", targetFile);
ImageHelper
.
CreateImage
(
"F:/Test/4.xls"
,
targetFile
);
//
ImageHelper.CreateImage("F:/Test/4.xls", targetFile);
return
ApiResult
.
Success
(
data
:
list
);
return
ApiResult
.
Success
(
data
:
list
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment