├── Pdfor部署说明.txt
├── Publish
├── DevOps
│ ├── release-cmd
│ │ ├── VsTool.exe
│ │ ├── 一键发布.bat
│ │ ├── 清理-所有.bat
│ │ ├── 三级版本号-改为preview版.bat
│ │ ├── 三级版本号-改为release版.bat
│ │ └── 三级版本号-改为下一temp版.bat
│ ├── github-bash
│ │ ├── 00.release.sh
│ │ ├── 71.file-zip.sh
│ │ ├── startup.bash
│ │ ├── 73.docker-image-build-push.sh
│ │ ├── 75.github-push-to-serset-release.sh
│ │ └── 76.github-push-release.sh
│ └── release-bash
│ │ ├── 51.docker-deploy-copy.sh
│ │ ├── 40.Station-publish(net5.0).sh
│ │ ├── 40.Station-publish(net6.0).sh
│ │ ├── 40.Station-publish(netcoreapp2.2).sh
│ │ ├── 40.Station-publish(netcoreapp3.0).sh
│ │ ├── 40.Station-publish(netcoreapp3.1).sh
│ │ ├── startup.bash
│ │ ├── 50.docker-image-create.sh
│ │ └── 40.Station-publish.sh
└── ReleaseFile
│ ├── docker-image
│ ├── pdfor
│ │ └── Dockerfile
│ └── 制作镜像.md
│ └── Station
│ └── Start Pdfor.bat
├── Pdfor
├── Module
│ ├── Logical
│ │ ├── IPdfConvert.cs
│ │ ├── LibReOffice
│ │ │ └── PdfConvert.cs
│ │ └── Office
│ │ │ └── PdfConvert.cs
│ └── Controllers
│ │ └── PdfController.cs
├── wwwroot
│ ├── index.html
│ └── Pdfor
│ │ └── ui
│ │ └── index.html
├── Properties
│ ├── launchSettings.json
│ └── PublishProfiles
│ │ └── FolderProfile.pubxml
├── Program.cs
├── Pdfor.csproj
├── Startup.cs
└── appsettings.json
├── libreoffice
├── docker
│ ├── libreoffice-dotnet2.1
│ │ ├── Dockerfile
│ │ ├── 制作镜像.txt
│ │ └── readme.md
│ └── libreoffice
│ │ ├── Dockerfile
│ │ ├── 制作镜像.txt
│ │ └── readme.md
└── libreoffice.txt
├── README.md
├── Pdfor.sln
└── .github
└── workflows
└── action-main.yml
/Pdfor部署说明.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vit-Lib/Pdfor/HEAD/Pdfor部署说明.txt
--------------------------------------------------------------------------------
/Publish/DevOps/release-cmd/VsTool.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vit-Lib/Pdfor/HEAD/Publish/DevOps/release-cmd/VsTool.exe
--------------------------------------------------------------------------------
/Publish/DevOps/release-cmd/一键发布.bat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vit-Lib/Pdfor/HEAD/Publish/DevOps/release-cmd/一键发布.bat
--------------------------------------------------------------------------------
/Publish/DevOps/release-cmd/清理-所有.bat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vit-Lib/Pdfor/HEAD/Publish/DevOps/release-cmd/清理-所有.bat
--------------------------------------------------------------------------------
/Publish/DevOps/release-cmd/三级版本号-改为preview版.bat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vit-Lib/Pdfor/HEAD/Publish/DevOps/release-cmd/三级版本号-改为preview版.bat
--------------------------------------------------------------------------------
/Publish/DevOps/release-cmd/三级版本号-改为release版.bat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vit-Lib/Pdfor/HEAD/Publish/DevOps/release-cmd/三级版本号-改为release版.bat
--------------------------------------------------------------------------------
/Publish/DevOps/release-cmd/三级版本号-改为下一temp版.bat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vit-Lib/Pdfor/HEAD/Publish/DevOps/release-cmd/三级版本号-改为下一temp版.bat
--------------------------------------------------------------------------------
/Publish/ReleaseFile/docker-image/pdfor/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM serset/libreoffice:dotnet2.1
2 | COPY app /root/app
3 | WORKDIR /root/app
4 | CMD dotnet Pdfor.dll
--------------------------------------------------------------------------------
/Publish/ReleaseFile/Station/Start Pdfor.bat:
--------------------------------------------------------------------------------
1 | start http://localhost:4301
2 |
3 | cd /d pdfor
4 |
5 | dotnet Pdfor.dll
6 |
7 |
8 | pause
9 |
10 | exit
--------------------------------------------------------------------------------
/Pdfor/Module/Logical/IPdfConvert.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Pdfor.Module.Logical
3 | {
4 | public interface IPdfConvert
5 | {
6 | bool ConvertToPdf(string filePath, string pdfFilePath);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Pdfor/wwwroot/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 正在跳转
5 |
6 |
7 |
8 | 正在跳转...
9 |
10 |
11 |
--------------------------------------------------------------------------------
/libreoffice/docker/libreoffice-dotnet2.1/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM microsoft/dotnet:2.1-aspnetcore-runtime
2 |
3 |
4 | FROM serset/libreoffice
5 |
6 | # dotnet runtime拷贝到容器中
7 | COPY --from=0 /usr/share/dotnet /usr/share/dotnet
8 |
9 | ENV ASPNETCORE_VERSION=2.1.24
10 | RUN ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
11 |
12 |
--------------------------------------------------------------------------------
/libreoffice/docker/libreoffice/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM centos:centos8.3.2011
2 |
3 | RUN yum install libreoffice-writer.x86_64 -y
4 | RUN yum install libreoffice-calc.x86_64 -y
5 | RUN yum install libreoffice-impress.x86_64 -y
6 |
7 | RUN yum install libreoffice-langpack-zh-Hans.x86_64 -y
8 |
9 | RUN yum groupinstall "Fonts" -y
10 | RUN yum groupinstall "Input Methods" -y
11 |
--------------------------------------------------------------------------------
/Publish/ReleaseFile/docker-image/制作镜像.md:
--------------------------------------------------------------------------------
1 |
2 | # docker login -u serset -p xxxxxxxxx
3 |
4 | #把本文件所在目录下的文件夹拷贝到image
5 |
6 | cd /root/image
7 | cd pdfor
8 |
9 | #构建镜像
10 | docker build -t serset/pdfor:1.1.4 -t serset/pdfor .
11 |
12 | #推送到镜像仓库
13 | docker push serset/pdfor:1.1.4
14 | docker push serset/pdfor
15 |
16 |
17 |
18 |
19 |
20 | #强制删除镜像名称中包含pdfor的镜像
21 | # docker rmi --force $(docker images | grep pdfor | awk '{print $3}')
22 |
23 |
--------------------------------------------------------------------------------
/Publish/DevOps/github-bash/00.release.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 |
5 | #----------------------------------------------
6 | #(x.1)当前路径
7 | curPath=$PWD
8 |
9 | cd $curPath/../release-bash
10 | export releaseBashPath=$PWD
11 |
12 |
13 |
14 |
15 | #----------------------------------------------
16 | #(x.2)
17 | cd $releaseBashPath
18 | bash startup.bash
19 |
20 |
21 |
22 |
23 |
24 |
25 | #----------------------------------------------
26 | #(x.9)
27 | #cd $curPath
28 |
--------------------------------------------------------------------------------
/libreoffice/docker/libreoffice/制作镜像.txt:
--------------------------------------------------------------------------------
1 | #构建镜像
2 |
3 | # docker login -u serset -p xxxxxxxxx
4 |
5 |
6 | #把本文件所在目录下的文件夹拷贝到 /root/image
7 |
8 | cd /home/ec2-user
9 | cd image
10 |
11 |
12 | #构建镜像并推送到 镜像仓库
13 | cd libreoffice
14 | docker build -t serset/libreoffice .
15 | cd ..
16 |
17 | docker push serset/libreoffice
18 |
19 |
20 |
21 |
22 | #强制删除镜像名称中包含adaptor_gateway的镜像
23 | # docker rmi --force $(docker images | grep libreoffice | awk '{print $3}')
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/libreoffice/docker/libreoffice-dotnet2.1/制作镜像.txt:
--------------------------------------------------------------------------------
1 | #构建镜像
2 |
3 | # docker login -u serset -p xxxxxxxxx
4 |
5 |
6 | #把本文件所在目录下的文件夹拷贝到 /root/image
7 |
8 | cd /home/ec2-user
9 | cd image
10 |
11 | #构建镜像
12 | cd libreoffice
13 | docker build -t serset/libreoffice:dotnet2.1 .
14 | cd ..
15 |
16 | #推送到镜像仓库
17 | docker push serset/libreoffice:dotnet2.1
18 |
19 |
20 |
21 |
22 | #强制删除镜像名称中包含adaptor_gateway的镜像
23 | # docker rmi --force $(docker images | grep libreoffice | awk '{print $3}')
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Pdfor/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:4301/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "web": {
12 | "commandName": "Project",
13 | "launchBrowser": true,
14 | "launchUrl": "index.html",
15 | "applicationUrl": "http://localhost:4301/"
16 | },
17 | "console": {
18 | "commandName": "Project",
19 | "launchBrowser": false
20 | }
21 |
22 | }
23 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Pdfor
2 |
3 | 代码地址:
4 |
5 | Pdfor为一款跨平台的pdf转换器。
6 | 可以把doc、docx、xls、xlsx、ppt、pptx 、html、txt 等文件转换为pdf格式。
7 | 通过http api方式对外提供服务,接口地址为 /Pdfor/ConvertToPdf。
8 | 运行环境为net core 2.1。
9 |
10 |
11 | linux平台支持LibReOffice驱动。
12 | windows平台支持使用Office 和 LibReOffice驱动。
13 |
14 |
15 |
16 | # docker部署
17 | pdfor可以通过docker部署,docker镜像地址为 serset/pdfor
18 |
19 | ``` bash
20 |
21 | # 前台启动
22 | docker run -it --rm -p 4301:4301 serset/pdfor
23 |
24 |
25 | # 后台启动
26 | docker run --name=pdfor --restart=always -d -p 4301:4301 serset/pdfor
27 |
28 | # 启动后访问 http://ip:4301
29 |
30 | ```
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Pdfor/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore;
2 | using Microsoft.AspNetCore.Hosting;
3 | using Vit.Extensions;
4 |
5 | namespace App
6 | {
7 | public class Program
8 | {
9 | public static void Main(string[] args)
10 | {
11 | CreateWebHostBuilder(args).Build().Run();
12 | }
13 |
14 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
15 | WebHost.CreateDefaultBuilder(args)
16 | .AllowAnyOrigin()
17 | .Populate()
18 | .UseServiceAdaptor()
19 | .UseUrls(Vit.Core.Util.ConfigurationManager.ConfigurationManager.Instance.GetByPath("server.urls"))
20 | .UseStartup()
21 | ;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Publish/DevOps/release-bash/51.docker-deploy-copy.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 | #---------------------------------------------------------------------
5 | #(x.1)参数
6 | args_="
7 |
8 | export basePath=/root/temp/svn
9 |
10 | # "
11 |
12 |
13 | #---------------------------------------------------------------------
14 | #(x.2)
15 | publishPath="$basePath/Publish/release/release/Station(net5.0)"
16 | dockerPath=$basePath/Publish/release/release/docker-deploy
17 |
18 |
19 |
20 | #----------------------------------------------
21 | echo "(x.3)copy dir"
22 |
23 | mkdir -p "$dockerPath/pdfor"
24 |
25 | \cp -f "$basePath/README.md" "$dockerPath/pdfor"
26 | \cp -f "$basePath/Pdfor部署说明.txt" "$dockerPath/pdfor"
27 |
28 | \cp -f "$publishPath/pdfor/appsettings.json" "$dockerPath/pdfor"
29 |
30 |
--------------------------------------------------------------------------------
/Publish/DevOps/release-bash/40.Station-publish(net5.0).sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 | #---------------------------------------------------------------------
5 | #(x.1)参数
6 | args_="
7 |
8 | export basePath=/root/temp/svn
9 |
10 | # "
11 |
12 |
13 | #----------------------------------------------
14 | echo "(x.2)netVersion"
15 | netVersion=net5.0
16 |
17 |
18 |
19 | #----------------------------------------------
20 | echo "(x.3)publish $netVersion"
21 |
22 | #修改csproj文件中的版本号
23 | cd $basePath
24 | sed -i 's/netcoreapp2.1/'"$netVersion"'/g' `grep -a '' . -rl --include *.csproj`
25 |
26 | cd $basePath/Publish/DevOps/release-bash
27 | bash 40.Station-publish.sh;
28 |
29 |
30 | #还原csproj文件中的版本号为netcoreapp2.1
31 | cd $basePath
32 | sed -i 's/'"$netVersion"'/netcoreapp2.1/g' `grep -a '' . -rl --include *.csproj`
33 |
34 |
35 | cd $basePath/Publish/DevOps/release-bash
36 |
37 |
--------------------------------------------------------------------------------
/Publish/DevOps/release-bash/40.Station-publish(net6.0).sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 | #---------------------------------------------------------------------
5 | #(x.1)参数
6 | args_="
7 |
8 | export basePath=/root/temp/svn
9 |
10 | # "
11 |
12 |
13 | #----------------------------------------------
14 | echo "(x.2)netVersion"
15 | netVersion=net6.0
16 |
17 |
18 |
19 | #----------------------------------------------
20 | echo "(x.3)publish $netVersion"
21 |
22 | #修改csproj文件中的版本号
23 | cd $basePath
24 | sed -i 's/netcoreapp2.1/'"$netVersion"'/g' `grep -a '' . -rl --include *.csproj`
25 |
26 | cd $basePath/Publish/DevOps/release-bash
27 | bash 40.Station-publish.sh;
28 |
29 |
30 | #还原csproj文件中的版本号为netcoreapp2.1
31 | cd $basePath
32 | sed -i 's/'"$netVersion"'/netcoreapp2.1/g' `grep -a '' . -rl --include *.csproj`
33 |
34 |
35 | cd $basePath/Publish/DevOps/release-bash
36 |
37 |
--------------------------------------------------------------------------------
/Publish/DevOps/release-bash/40.Station-publish(netcoreapp2.2).sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 | #---------------------------------------------------------------------
5 | #(x.1)参数
6 | args_="
7 |
8 | export basePath=/root/temp/svn
9 |
10 | # "
11 |
12 |
13 | #----------------------------------------------
14 | echo "(x.2)netVersion"
15 | netVersion=netcoreapp2.2
16 |
17 |
18 |
19 | #----------------------------------------------
20 | echo "(x.3)publish $netVersion"
21 |
22 | #修改csproj文件中的版本号
23 | cd $basePath
24 | sed -i 's/netcoreapp2.1/'"$netVersion"'/g' `grep -a '' . -rl --include *.csproj`
25 |
26 | cd $basePath/Publish/DevOps/release-bash
27 | bash 40.Station-publish.sh;
28 |
29 |
30 | #还原csproj文件中的版本号为netcoreapp2.1
31 | cd $basePath
32 | sed -i 's/'"$netVersion"'/netcoreapp2.1/g' `grep -a '' . -rl --include *.csproj`
33 |
34 |
35 | cd $basePath/Publish/DevOps/release-bash
36 |
37 |
--------------------------------------------------------------------------------
/Publish/DevOps/release-bash/40.Station-publish(netcoreapp3.0).sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 | #---------------------------------------------------------------------
5 | #(x.1)参数
6 | args_="
7 |
8 | export basePath=/root/temp/svn
9 |
10 | # "
11 |
12 |
13 | #----------------------------------------------
14 | echo "(x.2)netVersion"
15 | netVersion=netcoreapp3.0
16 |
17 |
18 |
19 | #----------------------------------------------
20 | echo "(x.3)publish $netVersion"
21 |
22 | #修改csproj文件中的版本号
23 | cd $basePath
24 | sed -i 's/netcoreapp2.1/'"$netVersion"'/g' `grep -a '' . -rl --include *.csproj`
25 |
26 | cd $basePath/Publish/DevOps/release-bash
27 | bash 40.Station-publish.sh;
28 |
29 |
30 | #还原csproj文件中的版本号为netcoreapp2.1
31 | cd $basePath
32 | sed -i 's/'"$netVersion"'/netcoreapp2.1/g' `grep -a '' . -rl --include *.csproj`
33 |
34 |
35 | cd $basePath/Publish/DevOps/release-bash
36 |
37 |
--------------------------------------------------------------------------------
/Publish/DevOps/release-bash/40.Station-publish(netcoreapp3.1).sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 | #---------------------------------------------------------------------
5 | #(x.1)参数
6 | args_="
7 |
8 | export basePath=/root/temp/svn
9 |
10 | # "
11 |
12 |
13 | #----------------------------------------------
14 | echo "(x.2)netVersion"
15 | netVersion=netcoreapp3.1
16 |
17 |
18 |
19 | #----------------------------------------------
20 | echo "(x.3)publish $netVersion"
21 |
22 | #修改csproj文件中的版本号
23 | cd $basePath
24 | sed -i 's/netcoreapp2.1/'"$netVersion"'/g' `grep -a '' . -rl --include *.csproj`
25 |
26 | cd $basePath/Publish/DevOps/release-bash
27 | bash 40.Station-publish.sh;
28 |
29 |
30 | #还原csproj文件中的版本号为netcoreapp2.1
31 | cd $basePath
32 | sed -i 's/'"$netVersion"'/netcoreapp2.1/g' `grep -a '' . -rl --include *.csproj`
33 |
34 |
35 | cd $basePath/Publish/DevOps/release-bash
36 |
37 |
--------------------------------------------------------------------------------
/Publish/DevOps/github-bash/71.file-zip.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 | #---------------------------------------------------------------------
5 | #(x.1)参数
6 | args_="
7 |
8 | export basePath=/root/temp/svn
9 |
10 | export version=`grep '' $(grep '\|' ${basePath} -r --include *.csproj -l | head -n 1) | grep -oP '>(.*)<' | tr -d '<>'`
11 |
12 | export name=pdfor
13 |
14 | # "
15 |
16 |
17 |
18 |
19 |
20 | #----------------------------------------------
21 | echo "压缩文件"
22 |
23 | docker run --rm -i \
24 | -v $basePath:/root/code \
25 | serset/filezip bash -c "
26 | set -e
27 |
28 | releasePath=/root/code/Publish/release
29 |
30 | for dirname in \`ls /root/code/Publish/release/release\`
31 | do
32 | if [ -d \$releasePath/release/\$dirname ]
33 | then
34 | filezip zip -p -i \$releasePath/release/\$dirname -o \$releasePath/release-zip/${name}-\${dirname}-${version}.zip
35 | fi
36 | done
37 |
38 | echo zip files:
39 | ls /root/code/Publish/release/release-zip
40 |
41 | "
--------------------------------------------------------------------------------
/Publish/DevOps/release-bash/startup.bash:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | # cd /root/temp/svn/Publish/DevOps/release-bash;bash startup.bash;
4 |
5 | #----------------------------------------------
6 | #(x.1)当前路径
7 | curPath=$PWD
8 |
9 | cd $curPath/../../..
10 | export basePath=$PWD
11 | cd $curPath
12 |
13 |
14 |
15 |
16 |
17 | #----------------------------------------------
18 | echo "(x.2)get version"
19 | export version=`grep '' $(grep '\|' ${basePath} -r --include *.csproj -l | head -n 1) | grep -oP '>(.*)<' | tr -d '<>'`
20 | echo $version
21 |
22 |
23 |
24 |
25 | #----------------------------------------------
26 | echo "(x.3)自动发布 $name-$version"
27 |
28 | for file in *.sh
29 | do
30 | echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 | echo "[$(date "+%H:%M:%S")]" bash $file
32 | bash $file
33 | done
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | #----------------------------------------------
42 | #(x.9)
43 | cd $curPath
44 |
--------------------------------------------------------------------------------
/Pdfor/Properties/PublishProfiles/FolderProfile.pubxml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 | FileSystem
9 | FileSystem
10 | Release
11 | Any CPU
12 |
13 | True
14 | False
15 | netcoreapp2.1
16 | 70d6f463-ab83-421c-89ba-d8c3fefbd0fe
17 | false
18 | <_IsPortable>true
19 | bin\Publish\
20 | True
21 |
22 |
--------------------------------------------------------------------------------
/Pdfor/wwwroot/Pdfor/ui/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | pdf转换服务
5 |
6 |
7 |
8 | pdf转换服务
9 |
10 | 转换doc、docx、xls、xlsx、ppt、pptx 、html、txt 等为pdf文件。
11 | 接口地址: /Pdfor/ConvertToPdf
12 |
13 |
14 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Publish/DevOps/github-bash/startup.bash:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | # cd /root/temp/svn/Publish/DevOps/github-bash;bash startup.bash;
4 |
5 |
6 |
7 | #----------------------------------------------
8 | #(x.1)当前路径
9 | curPath=$PWD
10 |
11 | cd $curPath/../../..
12 | export basePath=$PWD
13 | cd $curPath
14 |
15 |
16 | # export basePath=/root/temp/svn
17 |
18 | export name=pdfor
19 |
20 | #export DOCKER_USERNAME=serset
21 | #export DOCKER_PASSWORD=xxx
22 |
23 | #export NUGET_SERVER=https://api.nuget.org/v3/index.json
24 | #export NUGET_KEY=xxxxxxxxxx
25 |
26 | #export export GIT_SSH_SECRET=xxxxxx
27 |
28 |
29 | #----------------------------------------------
30 | echo "(x.2)get version"
31 | export version=`grep '' $(grep '\|' ${basePath} -r --include *.csproj -l | head -n 1) | grep -oP '>(.*)<' | tr -d '<>'`
32 | echo $version
33 |
34 |
35 |
36 | #----------------------------------------------
37 | #(x.3)bash
38 |
39 | for file in *.sh
40 | do
41 | echo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 | echo "[$(date "+%H:%M:%S")]" bash $file
43 | bash $file
44 | done
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/libreoffice/libreoffice.txt:
--------------------------------------------------------------------------------
1 |
2 | -----------------------------
3 | libreoffice
4 |
5 | https://zhuanlan.zhihu.com/p/137097200
6 | https://www.jianshu.com/p/bf2a86e1ef44?from=timeline
7 |
8 | docker run -it --rm -v /root/docker/office:/root/install centos:centos8.3.2011 /bin/bash
9 |
10 | #yum list libreoffice*
11 |
12 | # word pdf:writer_pdf_Export
13 | yum install libreoffice-writer.x86_64 -y
14 |
15 | # excel pdf:calc_pdf_Export
16 | yum install libreoffice-calc.x86_64 -y
17 |
18 | # ppt pdf:impress_pdf_Export
19 | yum install libreoffice-impress.x86_64 -y
20 |
21 |
22 | #
23 | yum install libreoffice-langpack-zh-Hans.x86_64 -y
24 |
25 | yum groupinstall "Fonts" -y
26 | yum groupinstall "Input Methods" -y
27 |
28 |
29 |
30 | ---------------------
31 | libreoffice --help
32 |
33 |
34 |
35 |
36 | libreoffice --headless --convert-to pdf --outdir "/root/install/" "/root/install/a.docx"
37 | libreoffice --headless --convert-to pdf --outdir "/root/install" "/root/install/xls.xls"
38 | libreoffice --headless --convert-to pdf --outdir "/root/install" "/root/install/ppt.pptx"
39 | -----------------------------
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/Pdfor.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29503.13
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pdfor", "Pdfor\Pdfor.csproj", "{51F8536E-7573-4721-9F36-767CB0717375}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {51F8536E-7573-4721-9F36-767CB0717375}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {51F8536E-7573-4721-9F36-767CB0717375}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {51F8536E-7573-4721-9F36-767CB0717375}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {51F8536E-7573-4721-9F36-767CB0717375}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {C7DA16E3-9949-49FA-B0B4-F830636DE60F}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/Publish/DevOps/release-bash/50.docker-image-create.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 | #---------------------------------------------------------------------
5 | #(x.1)参数
6 | args_="
7 |
8 | export basePath=/root/temp/svn
9 |
10 | # "
11 |
12 |
13 | #---------------------------------------------------------------------
14 | #(x.2)
15 | publishPath="$basePath/Publish/release/release/Station(netcoreapp2.1)"
16 | dockerPath=$basePath/Publish/release/release/docker-image
17 |
18 |
19 |
20 | #---------------------------------------------------------------------
21 | echo "(x.3)copy dir"
22 | \cp -rf "$basePath/Publish/ReleaseFile/docker-image/." "$dockerPath"
23 |
24 |
25 | #---------------------------------------------------------------------
26 | echo "(x.4)copy station"
27 | #查找所有需要发布的项目并copy
28 | cd $basePath
29 | for file in $(grep -a '' . -rl --include *.csproj)
30 | do
31 | cd $basePath
32 |
33 | #get publishName
34 | publishName=`grep '' $file -r | grep -oP '>(.*)<' | tr -d '<>'`
35 |
36 | #get dockerName
37 | dockerName=`grep '' $file -r | grep -oP '>(.*)<' | tr -d '<>'`
38 |
39 | echo copy $dockerName
40 | \cp -rf "$publishPath/$publishName/." "$dockerPath/$dockerName/app"
41 | done
42 |
43 |
44 |
--------------------------------------------------------------------------------
/libreoffice/docker/libreoffice-dotnet2.1/readme.md:
--------------------------------------------------------------------------------
1 | # docker部署libreoffice:dotnet2.1
2 |
3 |
4 | # 命令行启动容器
5 | > office文件存放在宿主机的/root/docker/libreoffice中并映射到容器,可按需修改。
6 | > libreoffice亦可改为soffice
7 |
8 | ``` bash
9 |
10 | docker run -it --rm -v /root/docker/libreoffice:/root/libreoffice serset/libreoffice:dotnet2.1 /bin/sh
11 |
12 |
13 | # libreoffice命令demo
14 |
15 | # 查看帮助
16 | libreoffice --help
17 |
18 | # 转换doc为pdf文件(转换后的文件为 /root/libreoffice/doc.pdf)
19 | libreoffice --headless --convert-to pdf --outdir "/root/libreoffice" "/root/libreoffice/doc.docx"
20 |
21 | # 转换xlsx为pdf文件
22 | libreoffice --headless --convert-to pdf --outdir "/root/libreoffice" "/root/libreoffice/xls.xlsx"
23 |
24 | # 转换pptx为pdf文件
25 | libreoffice --headless --convert-to pdf --outdir "/root/libreoffice" "/root/libreoffice/ppt.pptx"
26 |
27 | ```
28 |
29 |
30 |
31 | # 直接转换为pdf
32 | > office文件存放在宿主机的/root/docker/libreoffice中并映射到容器,可按需修改。
33 | > libreoffice亦可改为soffice
34 |
35 | ``` bash
36 |
37 | docker run -it --rm \
38 | -v /root/docker/libreoffice:/root/libreoffice \
39 | serset/libreoffice:dotnet2.1 \
40 | libreoffice "--headless" "--convert-to" pdf "--outdir" "/root/libreoffice" "/root/libreoffice/xls.xlsx"
41 |
42 |
43 | ```
--------------------------------------------------------------------------------
/Publish/DevOps/github-bash/73.docker-image-build-push.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 | #---------------------------------------------------------------------
5 | #(x.1)参数
6 | args_="
7 |
8 | export basePath=/root/temp/svn
9 |
10 | export version=`grep '' $(grep '\|' ${basePath} -r --include *.csproj -l | head -n 1) | grep -oP '>(.*)<' | tr -d '<>'`
11 |
12 | export DOCKER_USERNAME=serset
13 | export DOCKER_PASSWORD=xxx
14 |
15 | # "
16 |
17 |
18 |
19 |
20 |
21 |
22 | #---------------------------------------------------------------------
23 | #(x.3)docker-构建镜像并推送到 Docker Hub
24 |
25 | docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
26 |
27 |
28 | dockerPath=$basePath/Publish/release/release/docker-image
29 |
30 | for dockerName in `ls $dockerPath`
31 | do
32 | if [ -d $dockerPath/$dockerName ]
33 | then
34 | echo "docker build $dockerName"
35 | docker build -t $DOCKER_USERNAME/$dockerName:$version -t $DOCKER_USERNAME/$dockerName $dockerPath/$dockerName
36 |
37 | docker push $DOCKER_USERNAME/$dockerName:$version
38 | docker push $DOCKER_USERNAME/$dockerName
39 |
40 | docker rmi $DOCKER_USERNAME/$dockerName:$version
41 | docker rmi $DOCKER_USERNAME/$dockerName
42 | fi
43 | done
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/libreoffice/docker/libreoffice/readme.md:
--------------------------------------------------------------------------------
1 | # docker部署libreoffice
2 | libreoffice可以把doc、docx、xls、xlsx、ppt、pptx 、html、txt 等文件转换为pdf格式。
3 |
4 | # 命令行启动容器
5 | > office文件存放在宿主机的/root/docker/libreoffice中并映射到容器,可按需修改。
6 | > libreoffice亦可改为soffice
7 |
8 | ``` bash
9 |
10 | docker run -it --rm -v /root/docker/libreoffice:/root/libreoffice serset/libreoffice /bin/sh
11 |
12 |
13 | # libreoffice命令demo
14 |
15 | # 查看帮助
16 | libreoffice --help
17 |
18 | # 转换doc为pdf文件(转换后的文件为 /root/libreoffice/doc.pdf)
19 | libreoffice --headless --convert-to pdf --outdir "/root/libreoffice" "/root/libreoffice/doc.docx"
20 |
21 | # 转换xlsx为pdf文件
22 | libreoffice --headless --convert-to pdf --outdir "/root/libreoffice" "/root/libreoffice/xls.xlsx"
23 |
24 | # 转换pptx为pdf文件
25 | libreoffice --headless --convert-to pdf --outdir "/root/libreoffice" "/root/libreoffice/ppt.pptx"
26 |
27 | ```
28 |
29 |
30 |
31 | # 直接转换为pdf
32 | > office文件存放在宿主机的/root/docker/libreoffice中并映射到容器,可按需修改。
33 | > libreoffice亦可改为soffice
34 |
35 | ``` bash
36 |
37 | docker run -it --rm \
38 | -v /root/docker/libreoffice:/root/libreoffice \
39 | serset/libreoffice \
40 | libreoffice "--headless" "--convert-to" pdf "--outdir" "/root/libreoffice" "/root/libreoffice/xls.xlsx"
41 |
42 |
43 | ```
--------------------------------------------------------------------------------
/Publish/DevOps/github-bash/75.github-push-to-serset-release.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 | #---------------------------------------------------------------------
5 | #(x.1)参数
6 | args_="
7 |
8 | export basePath=/root/temp/svn
9 |
10 | export version=`grep '' $(grep '\|' ${basePath} -r --include *.csproj -l | head -n 1) | grep -oP '>(.*)<' | tr -d '<>'`
11 |
12 | export name=pdfor
13 |
14 | export export GIT_SSH_SECRET=xxxxxx
15 |
16 | # "
17 |
18 |
19 |
20 |
21 |
22 | #----------------------------------------------
23 | echo "github-提交release文件到serset/release仓库"
24 | # releaseFile=$basePath/Publish/release/release-zip
25 |
26 | #复制ssh key
27 | echo "${GIT_SSH_SECRET}" > $basePath/Publish/release/serset
28 | chmod 600 $basePath/Publish/release/serset
29 |
30 | #推送到github
31 | docker run -i --rm \
32 | -v $basePath/Publish/release:/root/release serset/git-client bash -c "
33 | set -e
34 | ssh-agent bash -c \"
35 | ssh-add /root/release/serset
36 | ssh -T git@github.com -o StrictHostKeyChecking=no
37 | git config --global user.email 'serset@yeah.com'
38 | git config --global user.name 'lith'
39 | mkdir -p /root/code
40 | cd /root/code
41 | git clone git@github.com:serset/release.git /root/code
42 | mkdir -p /root/code/file/${name}/${name}-${version}
43 | \\cp -rf /root/release/release-zip/. /root/code/file/${name}/${name}-${version}
44 | git add /root/code/file/${name}/${name}-${version}/.
45 | git commit -m 'auto commit ${version}'
46 | git push -u origin master \" "
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/Publish/DevOps/github-bash/76.github-push-release.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 | #---------------------------------------------------------------------
5 | #(x.1)参数
6 | args_="
7 |
8 | export basePath=/root/temp/svn
9 |
10 | export version=`grep '' $(grep '\|' ${basePath} -r --include *.csproj -l | head -n 1) | grep -oP '>(.*)<' | tr -d '<>'`
11 |
12 | export name=pdfor
13 |
14 | # "
15 |
16 |
17 |
18 |
19 |
20 | #---------------------------------------------------------------------
21 | #(x.2)构建github release环境变量
22 |
23 |
24 |
25 |
26 | echo "release_name=${name}-${version}" >> $GITHUB_ENV
27 | echo "release_tag=${version}" >> $GITHUB_ENV
28 |
29 | echo "release_draft=false" >> $GITHUB_ENV
30 | echo "release_prerelease=false" >> $GITHUB_ENV
31 |
32 | echo "release_body=" >> $GITHUB_ENV
33 |
34 |
35 | echo "release_dirPath=${basePath}/Publish/release/release-zip" >> $GITHUB_ENV
36 | echo "release_version=${version}" >> $GITHUB_ENV
37 |
38 | #filePath=$basePath/Publish/release/release-zip/Sers-ServiceCenter(net5.0)-${version}.zip
39 | #fileType="${filePath##*.}"
40 | #echo "release_assetPath=${filePath}" >> $GITHUB_ENV
41 | #echo "release_assetName=${name}-${version}.${fileType}" >> $GITHUB_ENV
42 | #echo "release_contentType=application/zip" >> $GITHUB_ENV
43 |
44 |
45 | # draft or preivew
46 | if [[ $version =~ "preview" ]]
47 | then
48 | echo preivew
49 | echo "release_prerelease=true" >> $GITHUB_ENV
50 | else
51 | if [[ "" = $(echo $version | tr -d "0-9\.") ]]
52 | then
53 | echo release
54 | else
55 | echo draft
56 | echo "release_draft=true" >> $GITHUB_ENV
57 | fi
58 | fi
59 |
60 |
--------------------------------------------------------------------------------
/Pdfor/Pdfor.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | pdfor
5 | pdfor
6 |
7 |
8 |
9 | netcoreapp2.1
10 |
11 | Exe
12 |
13 | 1.1.4
14 | https://github.com/serset/Pdfor
15 |
16 |
17 |
18 |
19 | bin\Debug\netcoreapp2.1\Pdfor.xml
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 | Always
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/Publish/DevOps/release-bash/40.Station-publish.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 |
4 | #---------------------------------------------------------------------
5 | #(x.1)参数
6 | args_="
7 |
8 | export basePath=/root/temp/svn
9 |
10 | # "
11 |
12 |
13 | #----------------------------------------------
14 | echo "(x.2)获取netVersion"
15 | netVersion=`grep '' $(grep '' ${basePath} -r --include *.csproj -l | head -n 1) | grep -oP '>(.*)<' | tr -d '<>'`
16 |
17 |
18 | publishPath=$basePath/Publish/release/release/Station\($netVersion\)
19 | echo publish Station
20 | echo dotnet version: $netVersion
21 |
22 |
23 | #----------------------------------------------
24 | echo "(x.3)查找所有需要发布的项目并发布"
25 |
26 |
27 | mkdir -p $publishPath
28 |
29 | docker run -i --rm \
30 | --env LANG=C.UTF-8 \
31 | -v $basePath/Publish/release/.nuget:/root/.nuget \
32 | -v $basePath:/root/code \
33 | serset/dotnet:sdk-6.0 \
34 | bash -c "
35 | set -e
36 |
37 | basePath=/root/code
38 | publishPath=\$basePath/Publish/release/release/Station\($netVersion\)
39 |
40 | #(x.3)查找所有需要发布的项目并发布
41 | cd \$basePath
42 | for file in \$(grep -a '' . -rl --include *.csproj)
43 | do
44 | cd \$basePath
45 |
46 | #get publishName
47 | publishName=\`grep '' \$file -r | grep -oP '>(.*)<' | tr -d '<>'\`
48 |
49 | echo publish \$publishName
50 |
51 | #publish
52 | cd \$(dirname \"\$file\")
53 | dotnet build --configuration Release
54 | dotnet publish --configuration Release --output \"\$publishPath/\$publishName\"
55 |
56 | #copy xml
57 | for filePath in bin/Release/$netVersion/*.xml ; do \\cp -rf \$filePath \"\$publishPath/\$publishName\";done
58 |
59 | done
60 |
61 |
62 | #(x.4)copy files
63 | \cp -rf \$basePath/Publish/ReleaseFile/Station/. \"\$publishPath\"
64 | \cp -f \$basePath/README.md \"\$publishPath\"
65 | \cp -f \$basePath/Pdfor部署说明.txt \"\$publishPath\"
66 |
67 |
68 | "
69 |
70 |
71 |
72 | echo 'publish succeed!'
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/Pdfor/Module/Logical/LibReOffice/PdfConvert.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.IO;
4 | using Vit.Core.Module.Log;
5 | using Vit.Core.Util.Shell;
6 |
7 | namespace Pdfor.Module.Logical.LibReOffice
8 | {
9 | public class PdfConvert : IPdfConvert
10 | {
11 | static readonly object locker = new object();
12 |
13 |
14 | public string fileName = "soffice";
15 |
16 | public string WorkingDirectory = null;
17 |
18 |
19 | #region ConvertToPdf
20 |
21 | ///
22 | /// 转换Office文件(doc、docx、xls、xlsx、ppt、pptx)为pdf文件
23 | ///
24 | ///
25 | ///
26 | /// 是否存在目的pdf文件
27 | public bool ConvertToPdf(string officeFilePath, string pdfFilePath)
28 | {
29 | if (!File.Exists(officeFilePath))
30 | {
31 | return false;
32 | }
33 |
34 | if (File.Exists(pdfFilePath))
35 | {
36 | File.Delete(pdfFilePath);
37 | }
38 |
39 | var outFileDir = pdfFilePath + "_temp";
40 | var outFilePath = Path.Combine(outFileDir, Path.GetFileNameWithoutExtension(officeFilePath) + ".pdf");
41 |
42 | string output;
43 | try
44 | {
45 | lock (locker)
46 | {
47 | // soffice --headless --convert-to pdf --outdir "/root/libreoffice" "/root/libreoffice/doc.docx"
48 | string arg = "--headless --convert-to pdf --outdir \"" + outFileDir + "\" \"" + officeFilePath + "\"";
49 | //最长转换时间半个小时
50 | bool success = OsShell.Shell(fileName, arg, out output, millisecondsOfWait: 30 * 60 * 1000,WorkingDirectory: WorkingDirectory);
51 |
52 | if (!success|| !File.Exists(outFilePath)) return false;
53 | }
54 | new FileInfo(outFilePath).MoveTo(pdfFilePath);
55 | return true;
56 | }
57 | catch (Exception ex)
58 | {
59 | Logger.Error(ex);
60 | throw;
61 | }
62 | finally
63 | {
64 | try
65 | {
66 | Directory.Delete(outFileDir);
67 | }
68 | catch { }
69 |
70 | }
71 |
72 | }
73 | #endregion
74 |
75 |
76 |
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/Pdfor/Startup.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Builder;
2 | using Microsoft.AspNetCore.Hosting;
3 | using Microsoft.AspNetCore.Http;
4 | using Microsoft.AspNetCore.Mvc;
5 | using Microsoft.Extensions.Configuration;
6 | using Microsoft.Extensions.DependencyInjection;
7 | using Vit.Extensions;
8 |
9 |
10 | namespace App
11 | {
12 |
13 | public class Startup
14 | {
15 | public Startup(IConfiguration configuration)
16 | {
17 | Configuration = configuration;
18 | }
19 |
20 | public IConfiguration Configuration { get; }
21 |
22 | // This method gets called by the runtime. Use this method to add services to the container.
23 | public void ConfigureServices(IServiceCollection services)
24 | {
25 | services.AddMvc(options =>
26 | {
27 | //使用自定义异常处理器
28 | options.Filters.Add();
29 |
30 | #if NETCOREAPP3_0_OR_GREATER
31 | options.EnableEndpointRouting = false;
32 | #endif
33 |
34 |
35 | })
36 | //设置兼容版本
37 | .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
38 |
39 |
40 | //配置上传文件 大小限制
41 | //https://blog.csdn.net/ddsthinkyou123/article/details/98850216
42 | services.Configure(x =>
43 | {
44 | x.MultipartBodyLengthLimit = 2000_000_000;//小于2000M
45 | });
46 |
47 |
48 | }
49 |
50 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
51 | public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env)
52 | {
53 | //配置静态文件
54 | foreach (var config in Vit.Core.Util.ConfigurationManager.ConfigurationManager.Instance.GetByPath("server.staticFiles"))
55 | {
56 | app.UseStaticFiles(config);
57 | }
58 |
59 |
60 | if (env.IsDevelopment())
61 | {
62 | app.UseDeveloperExceptionPage();
63 | }
64 | else
65 | {
66 | app.UseHsts();
67 | }
68 |
69 |
70 | #region api for appVersion
71 | app.Map("/version", appBuilder =>
72 | {
73 | appBuilder.Run(async context =>
74 | {
75 | var version= System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetEntryAssembly().Location).FileVersion;
76 | await context.Response.WriteAsync(version);
77 | });
78 |
79 | });
80 | #endregion
81 |
82 |
83 | //app.UseHttpsRedirection();
84 | app.UseMvc();
85 |
86 | }
87 | }
88 |
89 |
90 |
91 |
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/Pdfor/Module/Controllers/PdfController.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Mvc;
2 | using System;
3 | using System.Collections.Generic;
4 | using Microsoft.AspNetCore.Http;
5 | using System.IO;
6 | using System.Net;
7 | using Pdfor.Module.Logical;
8 |
9 | namespace BIMProduct.Module.Doc.Controllers
10 | {
11 |
12 | [Route("Pdfor")]
13 | [ApiController]
14 | public class PdfController : ControllerBase
15 | {
16 | string rootDir;
17 | public PdfController(Microsoft.AspNetCore.Hosting.IHostingEnvironment environment)
18 | {
19 | rootDir = Path.Combine(environment.WebRootPath,"Temp");
20 | }
21 |
22 | ///
23 | /// 转换office文件(word、excel、ppt)为pdf
24 | ///
25 | ///
26 | ///
27 | [HttpPost]
28 | [Route("ConvertToPdf")]
29 | [DisableRequestSizeLimit]
30 | public IActionResult ConvertToPdf([FromForm] IList files,[FromServices] IPdfConvert pdfConvert)
31 | {
32 | if (files == null || files.Count != 1)
33 | {
34 | Response.StatusCode = (int)HttpStatusCode.BadRequest;
35 | return new EmptyResult();
36 | }
37 |
38 |
39 | #region 保存文件并转换为pdf格式
40 | var oriFilePath = SaveFile(rootDir, files[0],addDateToPath: false);
41 | string pdfFilePath = oriFilePath + ".pdf";
42 | try
43 | {
44 | if (pdfConvert.ConvertToPdf(oriFilePath, pdfFilePath))
45 | {
46 | return File(System.IO.File.ReadAllBytes(pdfFilePath), "application/pdf", Path.ChangeExtension(files[0].FileName, ".pdf"));
47 | }
48 | }
49 | //catch (Exception ex)
50 | //{
51 | // throw;
52 | //}
53 | finally
54 | {
55 | try
56 | {
57 | if (System.IO.File.Exists(oriFilePath)) System.IO.File.Delete(oriFilePath);
58 | }
59 | catch { }
60 |
61 | try
62 | {
63 | if (System.IO.File.Exists(pdfFilePath)) System.IO.File.Delete(pdfFilePath);
64 | }
65 | catch { }
66 | }
67 |
68 | #endregion
69 |
70 | Response.StatusCode = (int)HttpStatusCode.BadRequest;
71 | return new EmptyResult();
72 | }
73 |
74 | #region 保存文件至临时文件夹
75 | ///
76 | /// wwwroot/Temp/2020-08/12/{HHmmss}_{random}_{FileName}.{txt}
77 | ///
78 | ///
79 | ///
80 | ///
81 | ///
82 | internal static string SaveFile(string basePath, IFormFile file, bool addDateToPath = true)
83 | {
84 | string filePath;
85 |
86 | string directoryPath = basePath;
87 |
88 | if (addDateToPath)
89 | directoryPath = Path.Combine(directoryPath, DateTime.Now.ToString("yyyy-MM"), DateTime.Now.ToString("dd"));
90 |
91 |
92 | Directory.CreateDirectory(directoryPath);
93 |
94 | do
95 | {
96 | var fileName = DateTime.Now.ToString("HHmmss") + "_" + new Random().Next(9999).ToString("D4") + "_" + Path.GetFileNameWithoutExtension(file.FileName) + Path.GetExtension(file.FileName);
97 |
98 | filePath = Path.Combine(directoryPath, fileName);
99 |
100 | } while (System.IO.File.Exists(filePath));
101 |
102 |
103 | using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
104 | {
105 | file.CopyTo(fs);
106 | }
107 | return filePath;
108 | }
109 |
110 |
111 |
112 | #endregion
113 | }
114 | }
--------------------------------------------------------------------------------
/.github/workflows/action-main.yml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with Actions
2 |
3 | name: CI
4 |
5 | # Controls when the action will run.
6 | on:
7 |
8 | push:
9 | # Triggers the workflow on push events but only for the master branch
10 | #branches: [ master ]
11 |
12 | # Triggers the workflow on push tag
13 | tags: ['*']
14 |
15 | # Allows you to run this workflow manually from the Actions tab
16 | workflow_dispatch:
17 |
18 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
19 | jobs:
20 | # This workflow contains a single job called "build"
21 | build:
22 | # The type of runner that the job will run on
23 | runs-on: ubuntu-latest
24 |
25 | # Steps represent a sequence of tasks that will be executed as part of the job
26 | steps:
27 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
28 | - uses: actions/checkout@v2
29 |
30 | # Runs a set of commands using the runners shell
31 | - name: Run startup.bash
32 | run: |
33 | set -e
34 | echo start build
35 | export DOCKER_USERNAME="${{ secrets.DOCKER_USERNAME }}"
36 | export DOCKER_PASSWORD="${{ secrets.DOCKER_PASSWORD }}"
37 | export GIT_SSH_SECRET="${{ secrets.GIT_SSH_SECRET }}"
38 | cd ./Publish/DevOps/github-bash
39 | bash startup.bash
40 | echo build succeed!
41 |
42 | echo "appName=pdfor" >> $GITHUB_ENV
43 |
44 |
45 | - name: release_create
46 | id: release_create
47 | uses: actions/create-release@v1
48 | #if: hashFiles(env.release_assetPath)
49 | env:
50 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51 | with:
52 | release_name: ${{ env.release_name }}
53 | tag_name: ${{ env.release_tag }}
54 | draft: ${{ env.release_draft }}
55 | prerelease: ${{ env.release_prerelease }}
56 | body: ${{ env.release_body }}
57 |
58 |
59 | # release_upload_asset
60 |
61 | - uses: actions/upload-release-asset@v1
62 | env:
63 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64 | with:
65 | upload_url: ${{ steps.release_create.outputs.upload_url }}
66 | asset_path: ${{ env.release_dirPath }}/${{ env.appName }}-docker-image-${{ env.release_version }}.zip
67 | asset_name: ${{ env.appName }}-docker-image-${{ env.release_version }}.zip
68 | asset_content_type: application/zip
69 |
70 | - uses: actions/upload-release-asset@v1
71 | env:
72 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73 | with:
74 | upload_url: ${{ steps.release_create.outputs.upload_url }}
75 | asset_path: ${{ env.release_dirPath }}/${{ env.appName }}-docker-deploy-${{ env.release_version }}.zip
76 | asset_name: ${{ env.appName }}-docker-deploy-${{ env.release_version }}.zip
77 | asset_content_type: application/zip
78 |
79 |
80 |
81 | - uses: actions/upload-release-asset@v1
82 | env:
83 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84 | with:
85 | upload_url: ${{ steps.release_create.outputs.upload_url }}
86 | asset_path: ${{ env.release_dirPath }}/${{ env.appName }}-Station(net5.0)-${{ env.release_version }}.zip
87 | asset_name: ${{ env.appName }}-Station-net5.0-${{ env.release_version }}.zip
88 | asset_content_type: application/zip
89 |
90 | - uses: actions/upload-release-asset@v1
91 | env:
92 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93 | with:
94 | upload_url: ${{ steps.release_create.outputs.upload_url }}
95 | asset_path: ${{ env.release_dirPath }}/${{ env.appName }}-Station(net6.0)-${{ env.release_version }}.zip
96 | asset_name: ${{ env.appName }}-Station-net6.0-${{ env.release_version }}.zip
97 | asset_content_type: application/zip
98 |
99 | - uses: actions/upload-release-asset@v1
100 | env:
101 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102 | with:
103 | upload_url: ${{ steps.release_create.outputs.upload_url }}
104 | asset_path: ${{ env.release_dirPath }}/${{ env.appName }}-Station(netcoreapp2.1)-${{ env.release_version }}.zip
105 | asset_name: ${{ env.appName }}-Station-netcoreapp2.1-${{ env.release_version }}.zip
106 | asset_content_type: application/zip
107 |
108 | - uses: actions/upload-release-asset@v1
109 | env:
110 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111 | with:
112 | upload_url: ${{ steps.release_create.outputs.upload_url }}
113 | asset_path: ${{ env.release_dirPath }}/${{ env.appName }}-Station(netcoreapp2.2)-${{ env.release_version }}.zip
114 | asset_name: ${{ env.appName }}-Station-netcoreapp2.2-${{ env.release_version }}.zip
115 | asset_content_type: application/zip
116 |
117 | - uses: actions/upload-release-asset@v1
118 | env:
119 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
120 | with:
121 | upload_url: ${{ steps.release_create.outputs.upload_url }}
122 | asset_path: ${{ env.release_dirPath }}/${{ env.appName }}-Station(netcoreapp3.0)-${{ env.release_version }}.zip
123 | asset_name: ${{ env.appName }}-Station-netcoreapp3.0-${{ env.release_version }}.zip
124 | asset_content_type: application/zip
125 |
126 | - uses: actions/upload-release-asset@v1
127 | env:
128 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129 | with:
130 | upload_url: ${{ steps.release_create.outputs.upload_url }}
131 | asset_path: ${{ env.release_dirPath }}/${{ env.appName }}-Station(netcoreapp3.1)-${{ env.release_version }}.zip
132 | asset_name: ${{ env.appName }}-Station-netcoreapp3.1-${{ env.release_version }}.zip
133 | asset_content_type: application/zip
--------------------------------------------------------------------------------
/Pdfor/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Warning"
5 | }
6 | },
7 |
8 | "Ioc": {
9 | "Services": [
10 |
11 | {
12 | /* 生命周期。可为 Scoped、Singleton、Transient。默认Scoped */
13 | "Lifetime": "Singleton",
14 | "Service": "Pdfor.Module.Logical.IPdfConvert",
15 |
16 | /* 使用微软Office进行转换,只支持window环境 */
17 | "///Implementation": "Pdfor.Module.Logical.Office.PdfConvert",
18 |
19 | /* 使用LibReOffice进行转换 */
20 | "Implementation": "Pdfor.Module.Logical.LibReOffice.PdfConvert",
21 |
22 | /* 使用LibReOffice进行转换,同时指定程序名或工作路径 */
23 | "//Implementation": {
24 | /* 动态加载的类名 */
25 | "className": "Pdfor.Module.Logical.LibReOffice.PdfConvert",
26 | "Invoke": [
27 | {
28 | //"WorkingDirectory": "",
29 | "fileName": "soffice"
30 | }
31 | ]
32 | }
33 | }
34 | ]
35 | },
36 |
37 |
38 |
39 |
40 |
41 |
42 | /* 微服务适配器 配置 */
43 | "//ServiceAdaptor": [
44 | {
45 | /* 在此Assembly中加载类 */
46 | "assemblyFile": "ServiceAdaptor.NetCore.Sers.dll",
47 | /* 动态加载的类名,必须继承接口 ServiceAdaptor.NetCore.IServiceAdaptor */
48 | "className": "ServiceAdaptor.NetCore.Sers.ServiceAdaptor"
49 |
50 | /* 配置 */
51 |
52 | },
53 | {
54 | /* 在此Assembly中加载类 */
55 | "assemblyFile": "ServiceAdaptor.NetCore.MinHttp.dll",
56 | /* 动态加载的类名,必须继承接口 ServiceAdaptor.NetCore.IServiceAdaptor */
57 | "//className": "ServiceAdaptor.NetCore.MinHttp.ServiceAdaptor",
58 |
59 | /* 配置 */
60 | /* 网关地址,必须指定 */
61 | "gatewayAddress": "http://127.0.0.1:6080",
62 | /* 超时时间(单位:秒,可不指定)。1小时 */
63 | "//timeoutSeconds": 3600
64 | },
65 | {
66 | /* 在此Assembly中加载类 */
67 | "assemblyFile": "ServiceAdaptor.NetCore.Consul.dll",
68 | /* 动态加载的类名,必须继承接口 ServiceAdaptor.NetCore.IServiceAdaptor */
69 | "//className": "ServiceAdaptor.NetCore.Consul.ServiceAdaptor",
70 |
71 | /* 配置 */
72 | /* 超时时间(单位:秒,可不指定)。1小时 */
73 | "//timeoutSeconds": 3600,
74 |
75 | /* consul的地址。如 http://127.0.0.1:8500 */
76 | "ConsulEndpoint": "http://127.0.0.1:8500",
77 |
78 | /* 提供的服务的地址,如 127.0.0.1、sers.cloud */
79 | "serviceHost": "127.0.0.1",
80 |
81 | /* 提供的服务的端口号 */
82 | "servicePort": 1106,
83 |
84 | /* 提供的服务的名称,如 ServiceProvider */
85 | "serviceName": "DevOpsDoc"
86 | }
87 |
88 | ],
89 |
90 |
91 | /* asp.net core 原始web服务配置 */
92 | "server": {
93 | "urls": [ "http://*:4301" ],
94 |
95 | /* 映射静态文件。若不指定则不映射静态文件 */
96 | "staticFiles": [
97 | {
98 |
99 | /* 静态文件路径。可为相对路径或绝对路径。若为空或空字符串则为默认路径(wwwroot)。demo:"wwwroot/demo" */
100 | //"rootPath": "wwwroot",
101 |
102 | /* 默认页面(可不指定)。An ordered list of file names to select by default. List length and ordering may affect performance */
103 | "defaultFileNames": ["index.html"],
104 |
105 | /* 静态文件类型映射配置的文件路径。可为相对路径或绝对路径。例如"contentTypeMap.json"。若不指定(或指定的文件不存在)则不指定文件类型映射配置 */
106 | //"contentTypeMapFile": "contentTypeMap.json",
107 |
108 | /* 回应静态文件时额外添加的http回应头。可不指定。 */
109 | "responseHeaders": {
110 |
111 | //设置浏览器静态文件缓存2592000秒(30天)
112 | "Cache-Control": "public,max-age=2592000"
113 | }
114 | }
115 | ]
116 | },
117 |
118 |
119 |
120 |
121 | /* Sers配置 begin */
122 | "Sers": {
123 | /* 通讯层配置 */
124 | "CL": {
125 | /* one conn is one channel.can be multiable */
126 | "Client": [
127 | {
128 | // Ipc.NamedPipe
129 | /* (x.1) type */
130 | /* 在此Assembly中查找Builder */
131 | "assemblyFile": "Sers.CL.Ipc.NamedPipe.dll",
132 | /* the class of Builder in assemblyFile */
133 | "className": "Sers.CL.Ipc.NamedPipe.OrganizeClientBuilder",
134 |
135 |
136 | /* (x.2) config */
137 | // 命名管道只支持本机或局域网。
138 | /* 服务端机器名或者ip地址(如 103.23.23.23 、win10f),默认 "." */
139 | "serverName": ".",
140 | /* 命名管道名称。例如: "Sers.CL.Ipc" */
141 | "pipeName": "Sers.CL.Ipc.4501",
142 | /* 连接秘钥,用以验证连接安全性。服务端和客户端必须一致 */
143 | "secretKey": "SersCL",
144 |
145 | /* 请求超时时间(单位ms,默认300000) */
146 | "requestTimeoutMs": 3600000
147 | },
148 | {
149 | // Socket.Iocp
150 | /* (x.1) type - Iocp */
151 | /* the class of builder in assemblyFile */
152 | //"className": "Sers.CL.Socket.Iocp.OrganizeClientBuilder",
153 |
154 | /* (x.2) conn config */
155 | /* 服务端 host地址。例如: "127.0.0.1"、"serset.com" */
156 | "host": "127.0.0.1",
157 | /* 服务端 监听端口号。例如: 4501 */
158 | "port": 4501,
159 | /* 连接秘钥,用以验证连接安全性。服务端和客户端必须一致 */
160 | "secretKey": "SersCL",
161 |
162 | /* 请求超时时间(单位ms,默认300000) */
163 | "requestTimeoutMs": 3600000
164 | }
165 | ]
166 | },
167 |
168 | /* LocalApiService 配置,可不指定 */
169 | "LocalApiService": {
170 |
171 | /* 是否 输出本地Api的调用信息到(ApiTrace)Log文件。默认:false */
172 | "//PrintTrace": true,
173 |
174 | "workThread": {
175 | // 模式,可为 LongThread(默认)、LongThread_TimeLimit、ManagedThread、ConsumerCascade
176 | "mode": "LongThread",
177 | /* 后台服务的线程个数(单位个,默认16)(0代表不开启服务) */
178 | "threadCount": 4,
179 | /* 最大线程数(包含常驻线程和临时线程),默认100。仅当mode为ManagedThread时有效 */
180 | "maxThreadCount": 100,
181 | /* 等待队列的最大长度(默认:100000)。仅当mode为LongThread_TimeLimit和ManagedThread时有效 */
182 | "pendingQueueLength": 100000,
183 | /* 超时时间(单位ms,默认300000),仅当mode为LongThread_TimeLimit、ManagedThread时有效 */
184 | "timeoutMs": 300000
185 | },
186 |
187 |
188 | /* 默认站点名称,可多个,可不指定 */
189 | "//apiStationNames": [ "demo" ]
190 | },
191 |
192 | /* ServiceStation配置,可不指定 */
193 | "ServiceStation": {
194 | /* serviceStation站点信息 */
195 | "serviceStationInfo": {
196 | /* 服务站点名称 */
197 | "serviceStationName": "Pdfor"
198 | }
199 | }
200 |
201 | },
202 |
203 | "serslot": {
204 | /* 额外api。SsApiDesc格式。除了系统api外,可以指定额外api。若指定返回数据(reply),则直接返回数据;若不指定返回数据,则由host进行处理 */
205 | "extApi": [
206 | {
207 | //路由(可为范接口,如 "/a/*" )
208 | "route": "/Pdfor/ui/*"
209 | }
210 | ]
211 | },
212 |
213 |
214 | /* Vit工具配置,可不指定 */
215 | "Vit": {
216 | /* 日志配置,可不指定 */
217 | "Logger": {
218 | /* print the log to Log/*.txt default:true */
219 | "PrintToTxt": true,
220 | /* print the log to console. default:true */
221 | "PrintToConsole": true
222 | }
223 | }
224 | /* Sers配置 end */
225 |
226 |
227 |
228 | }
229 |
--------------------------------------------------------------------------------
/Pdfor/Module/Logical/Office/PdfConvert.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Office.Core;
2 | using System;
3 | using System.IO;
4 | using Vit.Core.Module.Log;
5 | using Excel = Microsoft.Office.Interop.Excel;
6 | using PowerPoint = Microsoft.Office.Interop.PowerPoint;
7 | using Word = Microsoft.Office.Interop.Word;
8 |
9 | namespace Pdfor.Module.Logical.Office
10 | {
11 | public class PdfConvert:IPdfConvert
12 | {
13 |
14 |
15 | #region ConvertToPdf
16 |
17 | ///
18 | /// 转换Office文件(doc、docx、xls、xlsx、ppt、pptx)为pdf文件
19 | ///
20 | ///
21 | ///
22 | /// 是否存在目的pdf文件
23 | public bool ConvertToPdf(string officeFilePath, string pdfFilePath)
24 | {
25 | //File.Copy(officeFilePath, pdfFilePath);
26 | //return true;
27 |
28 | if (!File.Exists(officeFilePath))
29 | {
30 | return false;
31 | }
32 |
33 | if (File.Exists(pdfFilePath))
34 | {
35 | File.Delete(pdfFilePath);
36 | }
37 |
38 |
39 | switch (Path.GetExtension(officeFilePath)?.ToLower())
40 | {
41 | case ".doc":
42 | WordToPDF(officeFilePath, pdfFilePath);
43 | return true;
44 | case ".docx":
45 | WordToPDF(officeFilePath, pdfFilePath);
46 | return true;
47 | case ".xls":
48 | ExcelToPDF(officeFilePath, pdfFilePath);
49 | return true;
50 | case ".xlsx":
51 | ExcelToPDF(officeFilePath, pdfFilePath);
52 | return true;
53 | case ".ppt":
54 | PptToPDF(officeFilePath, pdfFilePath);
55 | return true;
56 | case ".pptx":
57 | PptToPDF(officeFilePath, pdfFilePath);
58 | return true;
59 | case ".pdf"://pdf不需要重新转化
60 | File.Copy(officeFilePath, pdfFilePath);
61 | return true;
62 | default: return false;
63 | }
64 | }
65 | #endregion
66 |
67 |
68 |
69 | #region CompareWord
70 | ///
71 | /// 比较前两个word文件的内容,并把比较结果保存到第三个word文件
72 | ///
73 | ///
74 | ///
75 | ///
76 | ///
77 | public static void CompareWord(string OriginalWord, string DestWord, string differentFile)
78 | {
79 | Microsoft.Office.Interop.Word._Application WordApp = null;
80 | try
81 | {
82 | #region (x.1)比较前两个word文件 比较结果为word
83 |
84 | WordApp = new Microsoft.Office.Interop.Word.Application();
85 | WordApp.Visible = false;
86 | Object oMissing = System.Reflection.Missing.Value;
87 | object sPath1 = OriginalWord;
88 | Word.Document doc1 = WordApp.Documents.Open(ref sPath1, ref oMissing,
89 | ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
90 | ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
91 |
92 | object sPath2 = DestWord;
93 | Word.Document doc2 = WordApp.Documents.Open(ref sPath2, ref oMissing,
94 | ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
95 | ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
96 | Word.Document doc3 = WordApp.CompareDocuments(doc1, doc2);
97 | #endregion
98 |
99 |
100 | #region (x.2)保存比较结果到word文件
101 | if (true)
102 | {
103 | //Type docsType = WordApp.Documents.GetType();
104 | doc3.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
105 | // 转换格式,另存为
106 | Type docType = doc3.GetType();
107 | object saveFileName = differentFile;
108 | docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc3,
109 | new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument });
110 |
111 | //保存
112 | WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
113 | WordApp = null;
114 | }
115 | #endregion
116 |
117 |
118 |
119 | #region //(x.3)保存比较结果到html文件
120 | if (false)
121 | {
122 | //Type docsType = WordApp.Documents.GetType();
123 | doc3.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
124 | // 转换格式,另存为
125 | Type docType = doc3.GetType();
126 | object saveFileName = differentFile;
127 | docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc3,
128 | new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML });
129 |
130 | //保存
131 | WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
132 | WordApp = null;
133 | }
134 | #endregion
135 |
136 |
137 | }
138 | finally
139 | {
140 | if (WordApp != null)
141 | {
142 | WordApp.Quit();
143 | WordApp = null;
144 | }
145 | }
146 | }
147 | #endregion
148 |
149 |
150 | #region 弃用 DataTableToExcel
151 |
152 | ///
153 | /// 把Excel文档转化为xls
154 | ///
155 | /// 数据
156 | ///
157 | private static byte[] DataTableToExcel(System.Data.DataTable table)
158 | {
159 | string htmlFileName = Path.GetTempFileName();
160 |
161 | Microsoft.Office.Interop.Excel._Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
162 | try
163 | {
164 | Object oMissing = System.Reflection.Missing.Value;
165 |
166 | //Workbook wb = ExcelApp.Workbooks.Open(System.Web.HttpContext.Current.Request.MapPath("temp/1.xlsx"));
167 | ExcelApp.UserControl = true;
168 | ExcelApp.DisplayAlerts = false;
169 | //为true时显示Excel表格
170 | ExcelApp.Visible = false;
171 |
172 |
173 | Excel.Workbook wb = ExcelApp.Workbooks.Add(oMissing);
174 | Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
175 | //导入数据的行数
176 | int nRowCount = table.Rows.Count;
177 | //导入字传的个数
178 | int nColCount = table.Columns.Count;
179 | object[,] objData = new object[nRowCount + 1, nColCount];
180 | for (int i = 0; i < nColCount; i++)
181 | {
182 | objData[0, i] = table.Columns[i].ColumnName;
183 | }
184 | for (int i = 0; i < nRowCount; i++)
185 | {
186 | System.Data.DataRow dr = table.Rows[i];
187 | for (int j = 0; j < nColCount; j++)
188 | {
189 | objData[i + 1, j] = dr[j];
190 | }
191 | }
192 |
193 | Microsoft.Office.Interop.Excel.Range r = ws.get_Range(ExcelApp.Cells[1, 1], ExcelApp.Cells[nRowCount + 1, nColCount]);
194 | r.NumberFormat = "@";
195 | r.Value2 = objData;
196 | r.EntireColumn.AutoFit();
197 | //object ofmt = Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel12;
198 | wb.SaveAs(htmlFileName, oMissing, oMissing, oMissing, oMissing, oMissing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, oMissing, oMissing, oMissing, oMissing, oMissing);
199 |
200 | //wb.SaveAs
201 |
202 | wb.Close(oMissing, oMissing, oMissing);
203 | return System.IO.File.ReadAllBytes(htmlFileName);
204 |
205 | }
206 | finally
207 | {
208 | ExcelApp.Quit();
209 | try
210 | {
211 | if (File.Exists(htmlFileName)) File.Delete(htmlFileName);
212 |
213 | }
214 | catch { }
215 | }
216 | }
217 | #endregion
218 |
219 |
220 | #region office -> html
221 |
222 |
223 | ///
224 | /// 把Word文档转化为Html文件
225 | ///
226 | /// word文件名
227 | /// 要保存的html文件名
228 | ///
229 | public static void WordToHtml(string wordFileName, string htmlFileName)
230 | {
231 | Word._Application WordApp = new Microsoft.Office.Interop.Word.Application();
232 | Object oMissing = System.Reflection.Missing.Value;
233 |
234 | try
235 | {
236 |
237 | WordApp.Visible = false;
238 | object filename = wordFileName;
239 | Microsoft.Office.Interop.Word._Document WordDoc = WordApp.Documents.Open(ref filename, ref oMissing,
240 | ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
241 | ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
242 |
243 | // Type wordType = WordApp.GetType();
244 | // 打开文件
245 | Type docsType = WordApp.Documents.GetType();
246 | WordDoc.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
247 | // 转换格式,另存为
248 | Type docType = WordDoc.GetType();
249 | object saveFileName = htmlFileName;
250 | docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, WordDoc,
251 | new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML });
252 |
253 | //保存
254 | WordDoc.Save();
255 |
256 | WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
257 | }
258 | finally
259 | {
260 | WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
261 | }
262 |
263 | }
264 |
265 |
266 | ///
267 | /// 把Excel文档转化为Html文件
268 | ///
269 | /// Excel文件名
270 | /// 要保存的html文件名
271 | ///
272 | public static void ExcelToHtml(string excelFileName, string htmlFileName)
273 | {
274 | Object oMissing = System.Reflection.Missing.Value;
275 | Microsoft.Office.Interop.Excel._Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
276 |
277 | try
278 | {
279 |
280 | ExcelApp.UserControl = true;
281 | ExcelApp.DisplayAlerts = false;
282 | //ExcelApp.Visible = true;
283 | object filename = excelFileName;
284 | Microsoft.Office.Interop.Excel._Workbook ExcelWorkbook = ExcelApp.Workbooks.Open(excelFileName, oMissing
285 | , oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
286 | oMissing, oMissing);
287 |
288 | ExcelWorkbook.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
289 | // 打开文件
290 | //Type docsType = ExcelApp.Workbooks.GetType();
291 | //// 转换格式,另存为
292 | //Type docType = ExcelWorkbook.GetType();
293 | //object saveFileName = htmlFileName;
294 | //docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, ExcelWorkbook,
295 | // new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML });
296 | object ofmt = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
297 | ExcelWorkbook.SaveAs(htmlFileName, ofmt, oMissing, oMissing, oMissing, oMissing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, oMissing, oMissing, oMissing, oMissing, oMissing);
298 |
299 |
300 | //保存
301 | ExcelWorkbook.Save();
302 | ExcelWorkbook.Close(oMissing, oMissing, oMissing);
303 |
304 | }
305 | finally
306 | {
307 | ExcelApp.Quit();
308 | }
309 |
310 | }
311 |
312 |
313 | ///
314 | /// 把Ppt文档转化为Html文件
315 | ///
316 | /// Ppt文件名
317 | /// 要保存的html文件名
318 | ///
319 | public static void PptToHtml(string pptFileName, string htmlFileName)
320 | {
321 | Object oMissing = System.Reflection.Missing.Value;
322 | Microsoft.Office.Interop.PowerPoint._Application PptApp = new Microsoft.Office.Interop.PowerPoint.Application();
323 | Microsoft.Office.Interop.PowerPoint.Presentation PptDoc=null;
324 |
325 | try
326 | {
327 |
328 | PptDoc = PptApp.Presentations.Open(pptFileName, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
329 | PptDoc.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
330 | PptDoc.SaveAs(htmlFileName, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, Microsoft.Office.Core.MsoTriState.msoTriStateMixed);
331 |
332 | }
333 | finally
334 | {
335 | PptDoc?.Close();
336 | PptApp.Quit();
337 | }
338 | }
339 | #endregion
340 |
341 |
342 | #region office -> pdf
343 |
344 |
345 |
346 |
347 | ///
348 | /// 将word文档转换成PDF格式
349 | ///
350 | ///
351 | ///
352 | ///
353 | public static void WordToPDF(string sourcePath, string targetPath)
354 | {
355 |
356 | Word.WdExportFormat exportFormat = Word.WdExportFormat.wdExportFormatPDF;
357 | object paramMissing = Type.Missing;
358 | Word.Application wordApplication = new Word.Application();
359 | Word.Document wordDocument = null;
360 | try
361 | {
362 | object paramSourceDocPath = sourcePath;
363 | string paramExportFilePath = targetPath;
364 |
365 | Word.WdExportFormat paramExportFormat = exportFormat;
366 | bool paramOpenAfterExport = false;
367 | Word.WdExportOptimizeFor paramExportOptimizeFor =
368 | Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
369 | Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument;
370 | int paramStartPage = 0;
371 | int paramEndPage = 0;
372 | Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent;
373 | bool paramIncludeDocProps = true;
374 | bool paramKeepIRM = true;
375 | Word.WdExportCreateBookmarks paramCreateBookmarks =
376 | Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
377 | bool paramDocStructureTags = true;
378 | bool paramBitmapMissingFonts = true;
379 | bool paramUseISO19005_1 = false;
380 |
381 | wordDocument = wordApplication.Documents.Open(
382 | ref paramSourceDocPath, ref paramMissing, ref paramMissing,
383 | ref paramMissing, ref paramMissing, ref paramMissing,
384 | ref paramMissing, ref paramMissing, ref paramMissing,
385 | ref paramMissing, ref paramMissing, ref paramMissing,
386 | ref paramMissing, ref paramMissing, ref paramMissing,
387 | ref paramMissing);
388 |
389 | if (wordDocument != null)
390 | wordDocument.ExportAsFixedFormat(paramExportFilePath,
391 | paramExportFormat, paramOpenAfterExport,
392 | paramExportOptimizeFor, paramExportRange, paramStartPage,
393 | paramEndPage, paramExportItem, paramIncludeDocProps,
394 | paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
395 | paramBitmapMissingFonts, paramUseISO19005_1,
396 | ref paramMissing);
397 |
398 | }
399 | finally
400 | {
401 | if (wordDocument != null)
402 | {
403 | wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
404 | wordDocument = null;
405 | }
406 |
407 | if (wordApplication != null)
408 | {
409 | wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
410 | wordApplication = null;
411 | }
412 |
413 | //GC.Collect();
414 | //GC.WaitForPendingFinalizers();
415 |
416 | }
417 | }
418 |
419 |
420 | ///
421 | /// 将excel文档转换成PDF格式
422 | ///
423 | ///
424 | ///
425 | ///
426 | public static void ExcelToPDF(string sourcePath, string targetPath)
427 | {
428 |
429 | Excel.XlFixedFormatType targetType = Excel.XlFixedFormatType.xlTypePDF;
430 |
431 | object missing = Type.Missing;
432 | Excel._Application application = null;
433 | Excel.Workbook workBook = null;
434 | try
435 | {
436 | application = new Excel.Application();
437 | object target = targetPath;
438 | object type = targetType;
439 | workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
440 | missing, missing, missing, missing, missing, missing, missing, missing, missing);
441 |
442 | workBook.ExportAsFixedFormat(targetType, target, Excel.XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
443 |
444 | }
445 | finally
446 | {
447 | if (workBook != null)
448 | {
449 | workBook.Close(true, missing, missing);
450 | workBook = null;
451 | }
452 | if (application != null)
453 | {
454 | application.Quit();
455 | application = null;
456 | }
457 |
458 | //GC.Collect();
459 | //GC.WaitForPendingFinalizers();
460 | }
461 |
462 | }
463 |
464 | ///
465 | /// 将ppt文档转换成PDF格式
466 | ///
467 | ///
468 | ///
469 | ///
470 | public static void PptToPDF(string sourcePath, string targetPath)
471 | {
472 |
473 |
474 | PowerPoint._Application application = null;
475 | PowerPoint.Presentation persentation = null;
476 | try
477 | {
478 | application = new PowerPoint.Application();
479 | persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
480 | persentation.SaveAs(targetPath, PowerPoint.PpSaveAsFileType.ppSaveAsPDF, Microsoft.Office.Core.MsoTriState.msoTrue);
481 | }
482 | finally
483 | {
484 | if (persentation != null)
485 | {
486 | persentation.Close();
487 | persentation = null;
488 | }
489 |
490 | if (application != null)
491 | {
492 | application.Quit();
493 | application = null;
494 | }
495 |
496 | //GC.Collect();
497 | //GC.WaitForPendingFinalizers();
498 | }
499 | }
500 | #endregion
501 | }
502 | }
503 |
--------------------------------------------------------------------------------