引用: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. 分布式Redis深度历险-复制

    Redis深度历险分为两个部分,单机Redis和分布式Redis. 本文为分布式Redis深度历险系列的第一篇,主要内容为Redis的复制功能. Redis的复制功能的作用和大多数分布式存储系统一样, ...

  2. jdk8 HashMap tableSizeFor

    今天读jdk8  HashMap源码,构造函数中 根据initialCapacity初始化threshold public HashMap(int initialCapacity, float loa ...

  3. 小鸟初学Shell编程(六)变量赋值

    变量的意义 我们在使用Linux命令或脚本的时候,会有一些输出,那么这些输出的信息可以用变量临时存储,以备我们下一条命令或脚本使用. 变量的定义 变量的定义建议用一个有意义的英文单词来代表变量,不要使 ...

  4. ios浏览器调试踩坑(1)----mescroll.js和vue-scroller

    主要记录在ios浏览器出现触摸无限加载的情况 使用vue-scroller和mescroll.js/mescroll.vue先踩ios浏览器默认滑动会影响mescroll的方法调用. 首先给公共js加 ...

  5. 车间如何数字化?MES系统来助力

    对于生产过程复杂多变的离散制造企业而言,面临重重考验:生产作业计划频繁变更,制造工艺复杂,在生产过程中的临时插单.材料短缺等现象.通过MES制造执行管理解决方案,搭建协同管理平台,加强控制力.执行力和 ...

  6. maven 学习---Maven构建自动化-Hudson

    建立自动化定义场景,依赖项目建设过程中被启动,一旦项目生成成功完成,以确保相关的项目是稳定的. 实例 考虑一个团队正在开发一个项目总线核心API上的其他两个项目的应用程序,网页UI和应用程序的桌面UI ...

  7. MySql学习笔记四

    MySql学习笔记四 5.3.数据类型 数值型 整型 小数 定点数 浮点数 字符型 较短的文本:char, varchar 较长的文本:text, blob(较长的二进制数据) 日期型 原则:所选择类 ...

  8. AssetBundleMaster_ReadMe_CN

    在开始使用之前, 建议先导入到一个空的工程里, 通过ReadMe的一步步引导使你对整个框架以及文件结构进行熟悉, 之后再考虑导入到现有工程中使用, 完整看完教程大概需要2个小时左右. 先看看文件夹结构 ...

  9. E09【餐厅】Can I have the bill,please?

    核心句型: Can I have the bill ,please? 请给我账单,好吗? 场景对话: A:Excuse me. Can I have the bill ,please? 你好,请给我账 ...

  10. JPA-save()方法会将字段更新为null的解决方法

    今天在开发上碰到一个问题,在做页面展示的时候传给前端十个字段,前端修改了其中3个的值,所以只传了3个值给后端,其余字段默认为null,更新后其他7个字段在全部变为了空值. 在前端没法全量回传所有属性的 ...