关于pageoffice如何生成PDF的代码
时间: 2023-08-26 08:07:14 浏览: 63
PageOffice可以通过以下代码生成PDF文件:
1. 引用PageOffice的COM组件
```
using PageOffice;
using PageOffice.Common;
using PageOffice.PageOfficeCOM;
```
2. 初始化PageOffice组件
```
PageOfficeCtrl poCtrl = new PageOfficeCtrl();
poCtrl.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
poCtrl.AddCustomToolButton("保存", "Save()", 1);
poCtrl.SaveFilePage = "savefile.aspx";
poCtrl.WebOpen("doc/test.doc", PageOffice.OpenModeType.docNormalEdit, "张三");
```
3. 生成PDF文件
```
poCtrl.SaveDocument(Server.MapPath("doc/test.pdf"), PageOffice.FileFormatType.PDF);
```
完整代码示例:
```
using PageOffice;
using PageOffice.Common;
using PageOffice.PageOfficeCOM;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
PageOfficeCtrl poCtrl = new PageOfficeCtrl();
poCtrl.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx";
poCtrl.AddCustomToolButton("保存", "Save()", 1);
poCtrl.SaveFilePage = "savefile.aspx";
poCtrl.WebOpen("doc/test.doc", PageOffice.OpenModeType.docNormalEdit, "张三");
poCtrl.SaveDocument(Server.MapPath("doc/test.pdf"), PageOffice.FileFormatType.PDF);
}
}
```
注意事项:
1. 需要在服务器上安装PageOffice组件;
2. 需要在PageOffice的服务器端页面(server.aspx)中添加保存代码(SaveFile);
3. 在生成PDF文件之前需要先打开要转换的文档。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)