从 WPF 打印 dwf/dwfx 文件

发布于 2024-07-27 16:18:30 字数 1007 浏览 9 评论 0原文

我目前正在尝试从 WPF 打印文档。 我正在使用网络浏览器,因为它包含一个 Active x 控件,该控件具有我需要查看文档的 autodesk 插件。

我知道 WPF 不直接支持 Web 浏览器,但我刚刚为此集成了 Windows 窗体库。 我已经设法让代码运行甚至打印,但是打印的文档是空白的。

我不确定 Windows 窗体库和 WPF 之间是否存在冲突; 我正在导航到该文档,并且仅在加载后才进行打印,并且没有抛出任何错误。

这是我正在使用的代码:

    private void btnPrint_Click(object sender, RoutedEventArgs e)
    {
        System.Windows.Forms.WebBrowser w = new System.Windows.Forms.WebBrowser();

        Uri uri = new Uri("C:\\BOS-BD-4518-000.dwg.dwf");
        w.Navigate(uri);

        w.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(w_DocumentCompleted);
    }

    void w_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
    {
        System.Windows.Forms.WebBrowser w = (System.Windows.Forms.WebBrowser)sender;

        w.Print();
    }

一种可能的问题可能是不允许加载活动 x 控件,是否有人知道如何强制初始化控件。

有谁对如何解决此问题或打印 Autodesk (.dwf) 文档的其他方法有任何想法

提前致谢, 苏姆盖伊

I'm currently attempting to print a document from WPF. I'm using the web browser because it contains an active x control which has the autodesk plugin which I need to view the document.

I'm aware that WPF doesn't directly support web browser but I've just integrated the Windows Forms library for this. I've managed to get the code running and even printing, however the document that prints is blank.

I'm not sure if it could possibly be a conflict between the Windows Forms library and WPF; I'm navigating to the document and only printing once it's loaded with no errors thrown.

Here's the code I'm using:

    private void btnPrint_Click(object sender, RoutedEventArgs e)
    {
        System.Windows.Forms.WebBrowser w = new System.Windows.Forms.WebBrowser();

        Uri uri = new Uri("C:\\BOS-BD-4518-000.dwg.dwf");
        w.Navigate(uri);

        w.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(w_DocumentCompleted);
    }

    void w_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
    {
        System.Windows.Forms.WebBrowser w = (System.Windows.Forms.WebBrowser)sender;

        w.Print();
    }

One possible hitch could be that the active x control is not being allowed to be load, does anyone know how to force the control to be initialised.

Does anyone have any ideas about how to solve this or another method of printing an autodesk (.dwf) document

Thanks in advance,
SumGuy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤寂小茶 2024-08-03 16:18:30

这并不是真正的答案,而是如果有人确实想要打印 .dwf 文件的话的解决方案。 不要,使用新形式 .dwfx。 这也是 Autodesk 正在切换的新文件类型,它实际上是 XPS 的一种形式,这使事情变得非常简单。 您可以将其加载到 Web 浏览器中,而无需使用 active x 或(这是更好的方法)使用 Visual Studio 中的 XPS 库,因为它可以非常简单地加载到 XPS 查看器中。

我最终用来打印可怕文件的代码如下:

private PrintQueue printQueue;

PrintDialog pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;

if (pDialog.ShowDialog() == true)
    PrintSystemJobInfo xpsPrintJob = printQueue.AddJob(v.FileName, v.FilePath, false);

那有多简单??? 使用 XPS 还有许多其他方法可以实现此目的。 您基本上可以将 dwfx 文件用作 XPS 文档

Not really an answer of sorts but a solution if anyone out does want to print a .dwf file. Don't, use the new form .dwfx. This is the new file type Autodesk are switching too and its actually a form of XPS which makes things quite easy. You can load it into a web browser without needing active x OR (this is the better way) use the XPS libraries in visual studio because it can be loaded very simply into an XPS viewer.

The code I eventually used to print the dreaded file is below:

private PrintQueue printQueue;

PrintDialog pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;

if (pDialog.ShowDialog() == true)
    PrintSystemJobInfo xpsPrintJob = printQueue.AddJob(v.FileName, v.FilePath, false);

How easy's that??? There are loads of other ways of doing it using XPS. You can basically just use the dwfx file as an XPS document

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文