C#.net word excel powerpoint (ppt) 转换成 pdf 文件

using System;
using System.Collections.Generic;
using
System.ComponentModel;
using System.Data;
using System.Drawing;
using
System.Linq;
using System.Text;
using System.Windows.Forms;

using Word = Microsoft.Office.Interop.Word;
using Excel =
Microsoft.Office.Interop.Excel;
using PowerPoint =
Microsoft.Office.Interop.PowerPoint;
using
Microsoft.Office.Core;

namespace ConvertToPDF
{
    public partial class Form1
: Form
    {

public
Form1()
       
{
           
InitializeComponent();
        }

private void button1_Click(object
sender, EventArgs e)
        {

if
(DOCConvertToPDF("C:/test.doc",
"C:/testD.pdf"))
           
{
               
MessageBox.Show("DOC转换成功!");
           
}
           
else
           
{
               
MessageBox.Show("对不起,转换失败!");
           
}

if
(XLSConvertToPDF("C:/test.xls",
"C:/testX.pdf"))
           
{
               
MessageBox.Show("XLS转换成功!");
           
}
           
else
           
{
               
MessageBox.Show("对不起,转换失败!");
           
}
            if
(PPTConvertToPDF("C:/需求提纲.pptx",
"C:/testP.pdf"))
           
{
               
MessageBox.Show("PPT转换成功!");
           
}
           
else
           
{
               
MessageBox.Show("对不起,转换失败!");
           
}
           
       
}
       
//Word转换成pdf
        ///
<summary>
        ///
把Word文件转换成为PDF格式文件
        ///
</summary>
        /// <param
name="sourcePath">源文件路径</param>
       
/// <param
name="targetPath">目标文件路径</param>
       
///
<returns>true=转换成功</returns>
       
private bool DOCConvertToPDF(string sourcePath, string
targetPath)
       
{
            bool
result=false;
           
Word.WdExportFormat exportFormat =
Word.WdExportFormat.wdExportFormatPDF;
           
object paramMissing =
Type.Missing;
           
Word.ApplicationClass wordApplication = new
Word.ApplicationClass();
           
Word.Document wordDocument =
null;
           
try
           
{
               
object paramSourceDocPath =
sourcePath;
               
string paramExportFilePath = targetPath;

Word.WdExportFormat paramExportFormat =
exportFormat;
               
bool paramOpenAfterExport =
false;
               
Word.WdExportOptimizeFor paramExportOptimizeFor =
Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
               
Word.WdExportRange paramExportRange =
Word.WdExportRange.wdExportAllDocument;
               
int paramStartPage =
0;
               
int paramEndPage =
0;
               
Word.WdExportItem paramExportItem =
Word.WdExportItem.wdExportDocumentContent;
               
bool paramIncludeDocProps =
true;
               
bool paramKeepIRM =
true;
               
Word.WdExportCreateBookmarks paramCreateBookmarks =
Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
               
bool paramDocStructureTags =
true;
               
bool paramBitmapMissingFonts =
true;
               
bool paramUseISO19005_1 = false;

wordDocument =
wordApplication.Documents.Open(
               
ref paramSourceDocPath, ref paramMissing, ref
paramMissing,
               
ref paramMissing, ref paramMissing, ref
paramMissing,
               
ref paramMissing, ref paramMissing, ref
paramMissing,
               
ref paramMissing, ref paramMissing, ref
paramMissing,
               
ref paramMissing, ref paramMissing, ref
paramMissing,
               
ref paramMissing);

if (wordDocument !=
null)
               
wordDocument.ExportAsFixedFormat(paramExportFilePath,
               
paramExportFormat,
paramOpenAfterExport,
               
paramExportOptimizeFor, paramExportRange,
paramStartPage,
               
paramEndPage, paramExportItem,
paramIncludeDocProps,
               
paramKeepIRM, paramCreateBookmarks,
paramDocStructureTags,
               
paramBitmapMissingFonts,
paramUseISO19005_1,
               
ref
paramMissing);
               
result =
true;
           
}
           
catch
           
{
               
result =
false;
           
}
           
finally
           
{
               
if (wordDocument !=
null)
               
{
                   
wordDocument.Close(ref paramMissing, ref paramMissing, ref
paramMissing);
                   
wordDocument =
null;
               
}
               
if (wordApplication !=
null)
               
{
                   
wordApplication.Quit(ref paramMissing, ref paramMissing, ref
paramMissing);
                   
wordApplication =
null;
               
}
               
GC.Collect();
               
GC.WaitForPendingFinalizers();
               
GC.Collect();
               
GC.WaitForPendingFinalizers();
           
}
            return
result;
       
}
        ///
<summary>
        ///
把Excel文件转换成PDF格式文件
        ///
</summary>
        /// <param
name="sourcePath">源文件路径</param>
       
/// <param
name="targetPath">目标文件路径</param>
       
///
<returns>true=转换成功</returns>
       
private bool XLSConvertToPDF(string sourcePath, string
targetPath)
       
{
            bool
result =
false;
           
Excel.XlFixedFormatType targetType =
Excel.XlFixedFormatType.xlTypePDF;
           
object missing =
Type.Missing;
           
Excel.ApplicationClass application =
null;
           
Excel.Workbook workBook =
null;
           
try
           
{
               
application = new
Excel.ApplicationClass();
               
object target =
targetPath;
               
object type =
targetType;
               
workBook = application.Workbooks.Open(sourcePath, missing, missing, missing,
missing,
missing,
                       
missing, missing, missing, missing, missing, missing, missing, missing,
missing);

workBook.ExportAsFixedFormat(targetType, target,
Excel.XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing,
missing,
missing);
               
result =
true;
           
}
           
catch
           
{
               
result =
false;
           
}
           
finally
           
{
               
if (workBook !=
null)
               
{
                   
workBook.Close(true, missing,
missing);
                   
workBook =
null;
               
}
               
if (application !=
null)
               
{
                   
application.Quit();
                   
application =
null;
               
}
               
GC.Collect();
               
GC.WaitForPendingFinalizers();
               
GC.Collect();
               
GC.WaitForPendingFinalizers();
           
}
            return
result;
       
}
        ///
<summary>
        ///
把PowerPoing文件转换成PDF格式文件
        ///
</summary>
        /// <param
name="sourcePath">源文件路径</param>
       
/// <param
name="targetPath">目标文件路径</param>
       
///
<returns>true=转换成功</returns>
       
private bool PPTConvertToPDF(string sourcePath, string
targetPath)
       
{
            bool
result;
           
PowerPoint.PpSaveAsFileType targetFileType =
PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
           
object missing =
Type.Missing;
           
PowerPoint.ApplicationClass application =
null;
           
PowerPoint.Presentation persentation =
null;
           
try
           
{
               
application = new
PowerPoint.ApplicationClass();
               
persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue,
MsoTriState.msoFalse,
MsoTriState.msoFalse);
               
persentation.SaveAs(targetPath, targetFileType,
Microsoft.Office.Core.MsoTriState.msoTrue);

result =
true;
           
}
           
catch
           
{
               
result =
false;
           
}
           
finally
           
{
               
if (persentation !=
null)
               
{
                   
persentation.Close();
                   
persentation =
null;
               
}
               
if (application !=
null)
               
{
                   
application.Quit();
                   
application =
null;
               
}
               
GC.Collect();
               
GC.WaitForPendingFinalizers();
               
GC.Collect();
               
GC.WaitForPendingFinalizers();
           
}
            return
result;
        }

}
}

C#.net word excel powerpoint (ppt) 转换成 pdf 文件,布布扣,bubuko.com

时间: 2024-08-11 07:40:48

C#.net word excel powerpoint (ppt) 转换成 pdf 文件的相关文章

怎样把ppt转换成pdf文件

怎样把ppt转换成pdf文件现在网上有很多可以把ppt文件转换为Fpdf文件的工具软件,但它们的生成质量相差甚远.大多通过这类软件转换生成的pdf文件图像清晰度.文字锐利度很差,而且ppt文件中重要的动画和过渡效果有可能全部消失.经过反复的对比测试,我认为此类软件中,迅捷ppt转换成pdf转换器当属佼佼者. 该软件支持文件转 Word.Excel.ppt.图片.Html等格式转换,支持多个文件的转换,另外增加了图片合并功能,可将多个图片存储在一个PDF文件中,这是目前为止没有一款软件能相比的.

PPT转换成PDF文件的方法

PPT转换成PDF文件的方法遇到个头疼的问题,要把PPT转换成PDF格式的文件,不知道该怎么办!在网上搜索了好久看到各种不同的软件,平时没有遇到过也没有使用过,现在好多软件一下都出来了,也不知道到底哪个软件才是比较好的.我平时比较讨厌下载软件,感觉麻烦下载安装什么的,所以希望找到一款有效的软件,这样就能省去试用的过程,当然也就只需要一次下载一次安装就能达到目的,多好.所以,我就在网上求助大家,让大家给我推荐一个比较好用的软件. 果然网络是万能的,热心的网友特别多,给出了宝贵的意见,大家普遍说好的

Word文档如何转换成PDF文件

Word文档是一种好编辑又好保存的文档,大家日常生活接触的也比较多.但随着PDF文件使用范围越来越广泛,很多Word文档大家都喜欢用PDF的格式来保存,这样安全性更高.接下来小编就介绍一下Word文档如何转换成PDF文件.1.格式之间的转换,就需要准备第三方操作工具来进行就会事半功倍,小伙伴们可自行在百度浏览器搜索PDF转换器将其下载下来安装到电脑上.2.鼠标双击打开转换器,直接进入操作页面,在操作页面的左边有五个功能,小伙伴们根据转换需要用鼠标点击选中第二个功能其他文件转PDF.3.点击其他文

怎么样把PPT转换成PDF文件使用

当ppt需要转换成pdf文件时,不外乎ppt文件不适合email转送.打印.网络分享.大家想要将自己的知识或是经验传到网上给更多的人分享.学习,又怕上传后版权的问题,毕竟你将ppt上传到网上也不能说就是你写的,有人下载后将里面的内容稍作更改后就变成自己的了,你也无处伸冤.pdf文件很好的保护了文件不被更改,为大家的心理设立一道防线,下面将给大家分享怎么把ppt转成pdf文件上传到网上的全过程,希望对您有所帮助. 第一步,首先请将一款转换中的重要工具下载并且按照步骤安装到电脑上,在浏览器中搜索"迅

PPT转换成PDF转换软件教程

PPT转换成PDF转换软件教程优秀的PPT转换成PDF转换器通常具备更为优秀的转换效果和质量,而普通的PPT转换PDF转换工具通常由于软件自身的转换技术问题,无法完整对PDF文件内容进行转换,大量的空白和乱码内容充斥整个转换之后的PDF文件内容,给用户也带来了极大的不便.无需下载安装,免费在线就能实现PPT转换成PDF文件完美转换.       借助优秀的PDF解析技术,迅捷PPT转换PDF转化软件成功地开发了云端服务版本.新的版本借助强大的云端平台的优势,无需用户安装下载软件也可以轻松地实现在

如何把excel文件转换成pdf文件

我们经常需要将excel文档转换成pdf文件,这是一种最简单.最方便的方法,视频播放地址:http://v.youku.com/v_show/id_XODM2MTk0NzI0.html

PPT转换成PDF转换器免费破解版

PPT转换成PDF转换器免费破解版对PPT转换成PDF文件内容进行编辑,最好办法是选择一款专业好用的PPT转换成PDF转换器,能适用于办公各种流行文件的转换,并且转换的效果要与原文保持一致.本章与大家分享一款转换效果出色的转换器——迅捷PPT转换成PDF转换器. PPT转换成PDF转换软件特征: ppt转换成pdf转换器完美的PPT转换成PDF文件识别技术: PPT转换成PDF转换器拥有先进的PPT转换成PDF文件识别技术,能够深入PPT转换成PDF文件内容进行扫描和分析,结合软件提供的转换接口

ppt转换成pdf转换器绿色版

ppt转换成pdf转换器绿色版批量办公文档转换软件,可以一次性批量地将Office办公文档换为pdf,支持命令行参数,使得转换工作可以自动运行,这里菜鸟把我的方法写下来,分享给朋友们,希望能帮到大家,更希望起到抛砖引玉的作用,有更好地方法被分享出来. 软件简介: 迅捷ppt转换成pdf转换器可用于Acrobat pdf文件批量转换为PowerPoint(幻灯片)演示文稿.ppt转换成pdf转换器是一个专业的pdf解决方案,将pdf转换为PowerPoint 2010,2007,2003,2000

什么转换器ppt转换成pdf效果好?

什么转换器ppt转换成pdf效果好?什么转换器可以简单有效的将ppt转换成pdf文档?答案毋庸置疑一定是迅捷pdf转换器.迅捷ppt转换成pdf转换器是目前国内最新技术,摒弃了之前转换器的转化率低.延时.乱码等问题,是一款高效的转换工具.如果朋友碰到office与pdf之间的相互转换,相信迅捷pdf转换器一定是你的理想选择. 虽然网上有很多pdf转换的软件,但是功能却是千差万别,而不同的差异也给我们带来了不一样的转换效果.大家在选择pdf转换器时,可以尝试用这几条标准来找到合适的pdf转换器.