WPF:流程文档转 PDF

标签 wpf pdf flowdocument xps

我,

是否有控件可以将流程文档内容打印为PDF?

编辑:不是第三方控件

谢谢

最佳答案

我能够通过将流程文档内容保存到 .DOCX 并使用 Microsoft.Office.Interop.Word 将其转换为 PDF 来解决我的问题

using moiw = Microsoft.Office.Interop.Word;


public static void WordToPDF(string docFileName)
    {
        // Create a new Microsoft Word application object
        moiw.Application word = new moiw.Application();

        // C# doesn't have optional arguments so we'll need a dummy value
        object oMissing = Missing.Value;

        // Get a Word file
        FileInfo wordFile = new FileInfo(docFileName);

        word.Visible = false;
        word.ScreenUpdating = false;

        // Cast as Object for word Open method
        Object filename = (Object)wordFile.FullName;

        // Use the dummy value as a placeholder for optional arguments
        moiw.Document doc = word.Documents.Open(ref filename, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing);
        doc.Activate();

        object outputFileName = wordFile.FullName.Replace(".docx", ".pdf");
        object fileFormat = moiw.WdSaveFormat.wdFormatPDF;

        // Save document into PDF Format
        doc.SaveAs(ref outputFileName,
            ref fileFormat, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing);

        // Close the Word document, but leave the Word application open.
        // doc has to be cast to type _Document so that it will find the
        // correct Close method.                
        object saveChanges = moiw.WdSaveOptions.wdDoNotSaveChanges;
        ((moiw._Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
        doc = null;

        // word has to be cast to type _Application so that it will find
        // the correct Quit method.
        ((moiw._Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
        word = null;
    }

关于WPF:流程文档转 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5334711/

相关文章:

wpf - OxyPlot WPF 不适用于按钮单击

c# - 如何从同一个类中的静态函数调用公共(public)事件?

wpf - 使用 WPF 时如何消除菜单字体模糊?

c# - 分页后 TableCell 拆分 : remainder split part loses original cell properties

c# - 从内存中删除 flowdocument 对象

c# - 将 RichTextBox 绑定(bind)到 FlowDocumentReader 内部的内容时,它变为只读

c# - Dispatcher 只从数组中提取最后一个对象

c# - 打印为 PDF 时字符串格式中的退格键

java - 从 PDF 中删除页面

pdf - PDF 词典的编码