将Office文档转换为PDF在C# [英] convert office documents to pdf in c#

查看:212
本文介绍了将Office文档转换为PDF在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要务实地将Office文档pdf.i不想使用Microsoft Office服务DDL。 这是code,我使用,

i want to pragmatically convert office documents to pdf.i do not want to use the microsoft office service ddl. this is the code which i used,

using System;
using System.IO;
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.IO.Compression;
using Document = Microsoft.Office.Interop.Word.Document;
   namespace pdfconversion
{
    public class PdfMerge
    {
        static void Main()
        {
            var wordApplication = new Microsoft.Office.Interop.Word.Application();
            Document wordDocument = null;
            object paramSourceDocPath = @"C:\testfile.doc";
            object paramMissing = Type.Missing;
            string paramExportFilePath = @"C:\Temp\Test1234.xps";
            WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatXPS;
            bool paramOpenAfterExport = false;
            WdExportOptimizeFor paramExportOptimizeFor =
                WdExportOptimizeFor.wdExportOptimizeForPrint;
            WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
            int paramStartPage = 0;
            int paramEndPage = 0;
            WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
            bool paramIncludeDocProps = true;
            bool paramKeepIRM = true;
            WdExportCreateBookmarks paramCreateBookmarks =
                WdExportCreateBookmarks.wdExportCreateWordBookmarks;
            bool paramDocStructureTags = true;
            bool paramBitmapMissingFonts = true;
            bool paramUseISO19005_1 = false;
                try
            {
                // Open the source document.
                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);
                   // Export it in the specified format.
                if (wordDocument != null)
                    wordDocument.ExportAsFixedFormat(paramExportFilePath,
                        paramExportFormat, paramOpenAfterExport,
                        paramExportOptimizeFor, paramExportRange, paramStartPage,
                        paramEndPage, paramExportItem, paramIncludeDocProps,
                        paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
                        paramBitmapMissingFonts, paramUseISO19005_1,
                        ref paramMissing);
            }
            catch (Exception ex)
            {
                // Respond to the error
            }
            finally
            {
                // Close and release the Document object.
                if (wordDocument != null)
                {
                    wordDocument.Close(ref paramMissing, ref paramMissing,
                        ref paramMissing);
                    wordDocument = null;
                }
                    // Quit Word and release the ApplicationClass object.
                if (wordApplication != null)
                {
                    wordApplication.Quit(ref paramMissing, ref paramMissing,
                        ref paramMissing);
                    wordApplication = null;
                }
                   GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();

我想用一个组件不是一个com.does人知道任何可能帮助我吗?我想itextsharp.it没有做转换。而cutepdf不能转化为直接的PDF。请帮助我走出this.i有试过的ghostscript。但其转换跋语PDF我无法找到一个方法来办公文档转换为.PS。有没有其他免费的图书馆,我可以用它来满足我的要求吗?

i want to use a assembly not a com.does anyone know anything that might help me?i tried itextsharp.it does not do the converting. and cutepdf is not able to convert to pdf directly. please help me out with this.i have tried ghostscript. but it converts postscripts to pdf i couldn't find a way to convert office documents to .ps. is there any other free library which i can use to meet my requirement?

请帮我在这里 感谢名单

please help me out here thanx

推荐答案

我最近看了很多免费的软件转换为PDF文件,我必须承认,他们没有被满足我的要求。有些转换是不坏,但该许可证是限制性。我想你将不得不寻找一个良好的非自由转换。

I've recently looked at lot of free softwares to convert documents to PDF and I must admit that none of them were meeting my requirements. Some converters were not bad but the licenses were to restrictive. I think you will have to find a good non free converter.

您可以去看看的PDF转换器,一个列表:转换器

You can take a look a this list of PDF converters: Converters

这篇关于将Office文档转换为PDF在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆