使用CutePDF打印PDF或通过c#打印备用工具

时间:2011-03-07 04:44:49

标签: c# pdf automation ms-word

我正在编写一个需要通过c#从word文档生成PDF的应用程序。我相信这可能是使用CutePDF的,尽管我会欢迎其他工具/ API的建议。有人有这方面的经验吗?

1 个答案:

答案 0 :(得分:2)

如果Word interop是一个选项,并且您拥有Word 2007或Word 2010,那么您可以让Word本身为您执行正常的另存为。

示例:

http://msdn.microsoft.com/en-us/library/bb412305(v=office.12).aspx

从上方链接引用示例代码:

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();
}