zoukankan      html  css  js  c++  java
  • .Net中World转PDF

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Aspose.Words;
    using System.IO;
    using Microsoft.Office.Interop.Word;

    namespace MyFilterTest.Tools
    {
    public class WorldTranslatePDF
    {
    public bool WordToPDF2(string sourcePath)
    {
    bool result = false;
    Application application = new Application();
    Microsoft.Office.Interop.Word.Document document = null;

    try

    {
    application.Visible = false;

    document = application.Documents.Open(sourcePath);

    string PDFPath = sourcePath.Replace(".doc", ".pdf");//pdf存放位置

    if (!File.Exists(PDFPath))//存在PDF,不需要继续转换

    {
    document.ExportAsFixedFormat(PDFPath, WdExportFormat.wdExportFormatPDF);
    }
    result = true;
    }
    catch (Exception e)
    {
    Console.WriteLine(e.Message);
    result = false;
    }
    finally
    {
    document.Close();
    }
    return result;
    }
    public bool WordToPDF1(string sourcePath)
    {
    try
    {
    Aspose.Words.Document doc = new Aspose.Words.Document(sourcePath);
    string targetPath = sourcePath.ToUpper().Replace(".DOCX", ".PDF");
    doc.Save(targetPath, SaveFormat.Pdf);
    }
    catch (Exception e)
    {
    Console.WriteLine(e.Message);
    return false;
    }
    return true;
    }

    }
    }

  • 相关阅读:
    Path Sum
    Intersection of Two Linked Lists (求两个单链表的相交结点)
    Nginx入门资料
    赛马问题
    翻转单词顺序 VS 左旋转字符串
    重建二叉树
    Fibonacci相关问题
    Find Minimum in Rotated Sorted Array(旋转数组的最小数字)
    常用查找算法总结
    Contains Duplicate
  • 原文地址:https://www.cnblogs.com/gsh0921/p/10444834.html
Copyright © 2011-2022 走看看