html asp,HTML asp 怎么

回答:ASP实现将Word等文档生成成PDF文档方法如下:

一、添加引用

using Microsoft.Office.Interop.Word;

二、转换方法

1、方法

C# 代码

///

/// 把Word文件转换成PDF文件

///

/// 需要转换的文件路径和文件名称

/// 转换完成后的文件的路径和文件名名称

/// 成功返回true,失败返回false

public static bool WordToPdf(string sourcePath, string targetPath)

{

bool reSUlt = false;

WdExportFormat wdExportFormatPDF = WdExportFormat.wdExportFormatPDF;//转换格式

1.wdExportFormatPDF转换成PDF格式 2.wdExportFormatXPS转换成xPS格式

object missing = Type.Missing;

Microsoft.Office.Interop.Word.ApplicationClass applicationClass = null;

Document document = null;

try

{

applicationClass = new Microsoft.Office.Interop.Word.ApplicationClass();

object inputfileName = sourcePath;//需要转格式的文件路径

string outputFileName = targetPath;//转换完成后PDF或XPS文件的路径和文件名名称

WdExportFormat exportFormat = wdExportFormatPDF;//导出文件所使用的格式

bool openAfterExport = false;//转换完成后是否打开

WdExportOptimizeFor wdExportOptimizeForPrint =

WdExportOptimizeFor.wdExportOptimizeForPrint;//导出方式1.wdExportOptimizeForPrint针对打印进

行导出,质量较高,生成的文件大小较大。2.wdExportOptimizeForOnScreen 针对屏幕显示进行导出,

质量较差,生成的文件大小较小。

WdExportRange wdExportAllDocument = WdExportRange.wdExportAllDocument;//导出全

部内容(枚举)

int from = 0;//起始页码

int to = 0;//结束页码

WdExportItem wdExportDocumentContent = WdExportItem.wdExportDocumentContent;//

指定导出过程中是否只包含文本或包含文本的标记.1.wdExportDocumentContent:导出文件没有标记,2.

导出文件有标记

bool includeDocProPS = true;//指定是否包含新导出的文件在文档属性

bool keepIRM = true;//

WdExportCreateBookmarks wdExportCreateWordBookmarks =

WdExportCreateBookmarks.wdExportCreateWordBookmarks;

//1.wdExportCreateNoBookmarks:不要在导出文件中创建书签

//2.wdExportCreateHeadingBookmarks:标题和文本框导出的文件中创建一个书签,

//3.wdExportCreateWordBookmarks每个字的书签,其中包括除包含页眉和页脚中的所有书签导出的文件中创建一个书签。

bool docStructureTags = true;

bool bitmapMissingFonts = true;

bool UseISO19005_1 = false;//生成的文档是否符合 ISO 19005-1 (PDF/A)

document = applicationClass.Documents.Open(ref inputfileName, ref missing, ref

missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref

missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

if (document != null)

{

document.ExportAsFixedFormat(outputFileName, exportFormat, openAfterExport,

wdExportOptimizeForPrint, wdExportAllDocument, from, to, wdExportDocumentContent,

includeDocProPS, keepIRM, wdExportCreateWordBookmarks, docStructureTags,

bitmapMissingFonts, UseISO19005_1, ref missing);

}

reSUlt = true;

}

catch

{

reSUlt = false;

}

finally

{

if (document != null)

{

document.Close(ref missing, ref missing, ref missing);

document = null;

}

if (applicationClass != null)

{

applicationClass.QUIt(ref missing, ref missing, ref missing);

applicationClass = null;

}

}

return reSUlt;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值