【问题标题】:PrintVisual prints empty PagePrintVisual 打印空白页
【发布时间】:2018-11-16 11:17:20
【问题描述】:

我正在尝试将一些 .png 文件直接打印到打印机。

所以我设置了这个功能:

    private void Print(string filepath)
    {
        LocalPrintServer printServer = new LocalPrintServer();
        PrintQueue printQueue = printServer.GetPrintQueue("PDFCreator");

        BitmapImage image = new BitmapImage();
        image.BeginInit();
        image.CacheOption = BitmapCacheOption.OnLoad;
        image.UriSource = new Uri(filepath);
        image.EndInit();


        PrintDialog printDialog = new PrintDialog
        {
            PrintQueue = printQueue
        };


        DrawingVisual visual = new DrawingVisual();
        var dc = visual.RenderOpen();
        dc.DrawImage(image, new System.Windows.Rect { Width = image.Width, Height = image.Height });

        printDialog.PrintVisual(visual, filepath);

    }

打印本身可以正常工作,但它只是打印一张空白纸。

【问题讨论】:

    标签: c# wpf printing


    【解决方案1】:

    您需要调用dc.Close() 将内容刷新到DrawingVisual。然后它就会有内容。

    【讨论】:

    • @josef_skywalker,没问题。魔鬼在细节中:)
    猜你喜欢
    • 2015-05-18
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    相关资源
    最近更新 更多