引用:https://www.jianshu.com/p/445996126c75

vs启动项目可以生成wps实例

本地iis部署的站点却不行

原因是vs是管理员权限,而iis没有权限

解决方法

启动IIS,应用程序池-“选定的应用程序池”-高级设置-进程模型-标识:设置为管理员账号administrator

 
 

代码

1.安装WPS 2016 专业版

2.方法一:在项目中引用etapi.dll,wpsapi.dll,wppapi.dll,在WPS的安装目录中,如C:\Program Files (x86)\Kingsoft\WPS Office\10.8.2.6666\office6

方法二:根据实际需要科添加下面的COM引用

原文:https://blog.csdn.net/xqf222/article/details/81237915

添加引用 -> COM -> Kingsoft Add-In Designer

添加引用 -> COM -> Microsoft Office 11.0 Object Library

添加引用 -> COM -> Upgrade WPS Office 3.0 Object Library(Beta)

添加引用 -> COM -> Upgrade WPS Presentation 3.0 Object Library(Beta)

添加引用 -> COM -> Upgrade Kingsoft WPS 3.0 Object Library(Beta)

添加引用 -> COM -> Kingsoft WPS Extend Apo 1.0 Object Library(Beta)

public class ToPdfHelper : IDisposable

{

dynamic wps;

public ToPdfHelper(string typeName)

{

if (typeName == "xls")

typeName = "KET.Application";

else if (typeName == "ppt")

typeName = "KWPP.Application";

else

typeName = "KWps.Application";

//创建wps实例,需提前安装wps

Type type = Type.GetTypeFromProgID(typeName);

if (type == null)

type = Type.GetTypeFromProgID("wps.Application");

wps = Activator.CreateInstance(type);

}

/// <summary>

/// 使用wps将Word转PDF

/// </summary>

/// <param name="saveUrl">文件路径</param>

/// <param name="targetPath">源文件路径</param>

/// <returns></returns>

public string WordWpsToPdf(string saveUrl, string targetPath)

{

if (targetPath == null)

{

throw new ArgumentNullException("wpsFilename");

}

var wordPath = saveUrl + targetPath;

var pdfPath = Path.ChangeExtension(wordPath, "pdf");

try

{

//用wps 打开word不显示界面

dynamic doc = wps.Documents.Open(wordPath, Visible: false);

//doc 转pdf

doc.ExportAsFixedFormat(pdfPath, WdExportFormat.wdExportFormatPDF);

//设置隐藏菜单栏和工具栏

//wps.setViewerPreferences(PdfWriter.HideMenubar | PdfWriter.HideToolbar);

doc.Close();

doc = null;

}

catch (Exception e)

{

targetPath = GetEXCELtoPDF.CreatePDFs(saveUrl, targetPath);

}

finally

{

Dispose();

}

return Path.ChangeExtension(targetPath, "pdf");

}

/// <summary>

/// 使用wps将xls转PDF

/// </summary>

/// <param name="saveUrl">文件路径</param>

/// <param name="targetPath">源文件路径</param>

/// <returns></returns>

public string XlsWpsToPdf(string saveUrl, string targetPath)

{

if (targetPath == null)

{

throw new ArgumentNullException("wpsFilename");

}

var wordPath = saveUrl + targetPath;

var pdfPath = Path.ChangeExtension(wordPath, "pdf");

try

{

XlFixedFormatType targetType = XlFixedFormatType.xlTypePDF;

object missing = Type.Missing;

//xls 转pdf

dynamic doc = wps.Application.Workbooks.Open(wordPath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

doc.ExportAsFixedFormat(targetType, pdfPath, XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);

//设置隐藏菜单栏和工具栏

//wps.setViewerPreferences(PdfWriter.HideMenubar | PdfWriter.HideToolbar);

doc.Close();

doc = null;

}

catch (Exception e)

{

targetPath = GetEXCELtoPDF.CreatePDFs(saveUrl, targetPath);

}

finally

{

Dispose();

}

return Path.ChangeExtension(targetPath, "pdf");

}

/// <summary>

/// 使用ppt将xls转PDF

/// </summary>

/// <param name="saveUrl">文件路径</param>

/// <param name="targetPath">源文件路径</param>

/// <returns></returns>

public string PptWpsToPdf(string saveUrl, string targetPath)

{

if (targetPath == null)

{

throw new ArgumentNullException("wpsFilename");

}

var wordPath = saveUrl + targetPath;

var pdfPath = Path.ChangeExtension(wordPath, "pdf");

try

{

//ppt 转pdf

dynamic doc = wps.Presentations.Open(wordPath, MsoTriState.msoCTrue,

MsoTriState.msoCTrue, MsoTriState.msoCTrue);

object missing = Type.Missing;

//doc.ExportAsFixedFormat(pdfPath, PpFixedFormatType.ppFixedFormatTypePDF,

//    PpFixedFormatIntent.ppFixedFormatIntentPrint,

//    MsoTriState.msoCTrue, PpPrintHandoutOrder.ppPrintHandoutHorizontalFirst,

//    PpPrintOutputType.ppPrintOutputBuildSlides,

//      MsoTriState.msoCTrue, null, PpPrintRangeType.ppPrintAll,"",

//      false, false, false, false, false, missing);

doc.SaveAs(pdfPath, PpSaveAsFileType.ppSaveAsPDF, MsoTriState.msoTrue);

//设置隐藏菜单栏和工具栏

//wps.setViewerPreferences(PdfWriter.HideMenubar | PdfWriter.HideToolbar);

doc.Close();

doc = null;

}

catch (Exception e)

{

targetPath = GetEXCELtoPDF.CreatePDFs(saveUrl, targetPath);

}

finally

{

Dispose();

}

return Path.ChangeExtension(targetPath, "pdf");

}

public void Dispose()

{

if (wps != null) { wps.Quit(); wps = null; }

}

}

C#调用WPS将文档转换成pdf进行预览的更多相关文章

  1. word ppt excel文档转换成pdf

    1.把word文档转换成pdf (1).添加引用 using Microsoft.Office.Interop.Word; 添加引用 (2).转换方法 /// <summary> /// ...

  2. C#实现文档转换成PDF

    网上有很多将doc.ppt.xls等类型的文档转换成pdf的方法,目前了解到的有两大类: 1.使用虚拟打印机将doc.ppt.xls等类型的文档 2.使用OFFICE COM组件 我采用了第二种方法实 ...

  3. ASP.NET将word文档转换成pdf的代码

    一.添加引用 using Microsoft.Office.Interop.Word; 二.转换方法 1.方法 C# 代码 /// <summary> /// 把Word文件转换成pdf文 ...

  4. asp.net将ppt文档转换成pdf

    一.添加引用 using Microsoft.Office.Core;using Microsoft.Office.Interop.PowerPoint; 二.转换方法   C# 代码   复制 // ...

  5. Python将word文档转换成PDF文件

    如题. 代码: ''' #將word文档转换为pdf文件 #用到的库是pywin32 #思路上是调用了windows和office功能 ''' #导入所需库 from win32com.client ...

  6. Java利用aspose-words将word文档转换成pdf(破解 无水印)

    首先下载aspose-words-15.8.0-jdk16.jar包 http://pan.baidu.com/s/1nvbJwnv 引入jar包,编写Java代码 package doc; impo ...

  7. Java实现批量将word文档转换成PDF

    先导入words的jar包 需要jar包的私聊我发你 代码如下:import com.aspose.words.Document;import java.io.File; public class W ...

  8. C# word文档转换成PDF格式文档

    最近用到一个功能word转pdf,有个方法不错,挺方便的,直接调用即可,记录下 方法:ConvertWordToPdf(string sourcePath, string targetPath) so ...

  9. JAVA:借用OpenOffice将上传的Word文档转换成Html格式

    为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...

随机推荐

  1. Java JDK和IntelliJ IDEA 配置及安装

    序言 初学java,idea走一波先.安装完成,配置配置项. idea 软件 官方下载地址:https://www.jetbrains.com/idea/download/#section=windo ...

  2. java 微信自定义菜单 java微信接口开发 公众平台 SSM redis shiro 多数据源

    A 调用摄像头拍照,自定义裁剪编辑头像,头像图片色度调节B 集成代码生成器 [正反双向](单表.主表.明细表.树形表,快速开发利器)+快速表单构建器 freemaker模版技术 ,0个代码不用写,生成 ...

  3. Logback文件这么配置,TPS提高至少10倍

    来源:https://tinyurl.com/y5zbtgsq 阅读本文,你将了解到 日志输出到文件并根据LEVEL级别将日志分类保存到不同文件 通过异步输出日志减少磁盘IO提高性能 异步输出日志的原 ...

  4. Comet 67E: ffort

    题目传送门:Comet 67E. 用了个傻逼做法 A 了这题,欢迎观赏睿智做法! 题意简述: 题目说得很清楚了(这次是我不想写了). 题解: 为了方便,令 \(m\) 为敌人数,\(n\) 为己方士兵 ...

  5. 17-numpy笔记-莫烦pandas-5

    代码 import pandas as pd import numpy as np left=pd.DataFrame({'key':['K0','K1','K2','K3'], 'A':['A0', ...

  6. 重新学习SpringMVC——高级

    30. SpringMVC_RESTRUL_CRUD_显示所有员工信息31. SpringMVC_RESTRUL_CRUD_添加操作&表单标签32. SpringMVC_RESTRUL_CRU ...

  7. C++17尝鲜

    https://cloud.tencent.com/developer/article/1351910 [译]C++17,optional, any, 和 variant 的更多细节 用户261520 ...

  8. USACO River Crossing

    洛谷 P2904 [USACO08MAR]跨河River Crossing https://www.luogu.org/problem/P2904 JDOJ 2574: USACO 2008 Mar ...

  9. Nexus 私服上传文件,并通过 Gradle 引用

    一.上传文件到 Nexus 1,进入 Nexus 仓库界面 如果你电脑还没有使用 Nexus,需要先下载并启动 Nexus 私服. 在浏览器输入:http://127.0.0.1:8081/nexus ...

  10. Excel 日期和时间函数

    1.TODAY和NOW函数 today和now函数 日期可以进行加减运算 2.提取日期和时间的函数 公式=Year() 公式=month() 公式=day() 公式=hour() 公式=minute( ...