【问题标题】:Printing word document with margins out of printable area打印带有超出可打印区域的边距的word文档
【发布时间】:2011-12-19 08:12:54
【问题描述】:

我有一个打印word文档的代码。 在示例文档中,有一个图片部分已被用户修改了边距。

当我执行代码时,我收到以下消息:

第 1 部分的边距设置在可打印区域之外。

处理文档后,它开始假脱机并抛出此提示 如何关闭通知对话框?

到目前为止我的代码:

        Process printJob = new Process();
        printJob.StartInfo.Verb = "PrintTo";
        printJob.StartInfo.Arguments = printerName;
        printJob.StartInfo.ErrorDialog = false;
        printJob.StartInfo.CreateNoWindow = true;
        printJob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        printJob.StartInfo.FileName = path;
        printJob.StartInfo.UseShellExecute = true;
        printJob.StartInfo.Verb = "print";
        printJob.Start();

其中变量路径>是文件名路径

【问题讨论】:

    标签: c# windows printing


    【解决方案1】:

    http://word.mvps.org/faqs/macrosvba/OutsidePrintableArea.htm

    据此,您需要关闭后台打印,然后关闭 Application.DisplayAlerts。

    编辑

    Process 无法做到这一点。 “打印”动词使用 /x /dde 告诉 Word 打印:

    /x 从操作外壳启动 Word 的新实例(例如,在 Word 中打印)。此 Word 实例仅响应一个 DDE 请求并忽略所有其他 DDE 请求和多实例。如果您在操作环境(例如,在 Windows)中启动 Word 的新实例,建议您使用 /w 开关,它会启动一个功能齐全的实例。

    要抑制消息,您需要改为进行互操作:

    1. 添加对 Microsoft.Office.Interop.Word 的引用
    2. 创建一个Print(string path) 方法:
    Application wordApp = new Application();
    wordApp.Visible = false;
    
    //object missing = Type.Missing;
    
    wordApp.Documents.Open(path); //for VS 2008 and earlier - just give missing for all the args
    
    wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone;
    wordApp.ActiveDocument.PrintOut(false); //as before - missing for remaining args, if using VS 2008 and earlier
    
    wordApp.Quit(WdSaveOptions.wdDoNotSaveChanges); //ditto
    

    【讨论】:

    • 我看不出这对我有什么帮助,因为我没有应用程序,只有控制台。
    • 查看我的编辑。当您的要求非常简单时,流程打印非常适合。
    • 这就是我所缺少的。你知道如何强制它双面打印吗?
    • (wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone; 仍然为我弹出提示。)
    • @cederlof 后台打印也关闭了吗?
    猜你喜欢
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    • 2012-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多