admin管理员组

文章数量:1605636

将Word转换为带目录书签的PDF,待转换Word中应该有目录或书签,可以用Word中的标题来自动生成目录

office.interop.word 转pdf

public bool WordToPDF(string sourcePath, string targetPath)
    {
        bool result = false;
        Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();
        Microsoft.Office.Interop.Word.Document document = null;
        try
        {             
            application.Visible = false;
            document = application.Documents.Open(sourcePath);
            document.ExportAsFixedFormat(targetPath, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
            result = true;
        }
        catch (Exception e)
        {
            LogHelper.info(GetType(), e, Level.Error);
            result = false;
        }
        finally
        {
            document.Close();
        }
        return result;
    }

问题 解决方法

本文标签: wordPDF