【问题标题】:WPF Vector Printing - Send DrawingGroup as Vector to printerWPF 矢量打印 - 将绘图组作为矢量发送到打印机
【发布时间】:2015-09-23 20:19:42
【问题描述】:

我想使用 WPF 以编程方式打印。但是,我需要将所有材料以矢量图而不是光栅图形发送到打印机。

主要问题是,我无法让 WPF 打印矢量图形,打印件总是被光栅化。

我使用SharpVectors,它将 .svg 文件转换为 am .xaml 绘图组。然后将该绘图组插入到流文档中的图像中,最后我使用 XPSDocumentWriter 将流文档发送到打印。

每次都模糊。我将打印与从 adobe Illustrator 打印的 .svg 文件进行比较。昼夜质量。

有没有什么办法可以让一个绘图组始终打印为矢量?

我正在为此提供赏金。您必须提交将以下绘图组作为矢量图形发送到打印机所需的 c# 代码,这必须是可重现的才能获得赏金。此外,在图像被光栅化后简单地增加 DPI 并不能作为答案。没有矢量打印 - 没有赏金。

https://drive.google.com/file/d/0B-M6Yes83t08V0ZOOEp1Q3dEYjA/view?usp=sharing Google Drive DrawingGroup xaml

【问题讨论】:

  • 看起来这在 6 年前就已经是个问题了:stackoverflow.com/questions/6286665/… - 所以也许你最好使用 svg-to-GDI 库,例如 github.com/vvvv/SVG
  • 我在这些库中没有看到任何将 SVG 作为矢量发送到打印的东西。它们都是帮助在显示器上呈现而不是打印的工具。我认为 GDI 只是光栅图形。

标签: wpf xaml vector printing raster


【解决方案1】:

是的,你可以! ;-) 我认为您最好忘记图像并使用 FixedDocument

首先创建一个类,覆盖 OnRender :

public partial class MapDrawingElement : FrameworkElement
{
    public MapDrawingElement()
    {
        InitializeComponent();
    }
    protected override void OnRender(DrawingContext drawingContext)
    {
        base.OnRender(drawingContext);
        var res = Resources["drawingGroup1"] as DrawingGroup;
        if (res != null)
            drawingContext.DrawDrawing(res);
    }
}

该类在其资源部分中有一个 drawingGroup1 资源:

<FrameworkElement x:Class="DemoFixedpageDocument.MapDrawingElement"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="800" d:DesignWidth="800">
    <FrameworkElement.Resources>
        <DrawingGroup x:Key="drawingGroup1">
... here your xaml 16k lines ! ...
        </DrawingGroup>
    </FrameworkElement.Resources>
</FrameworkElement>

实例化一个FixedDocument,并将带有地图的控件放在一个页面中:

public static class DocumentMaker
{
    public static FixedDocument GenerateFixedDocument()
    {
        FixedDocument fixedDocument = new FixedDocument();
        PageContent pageContent1 = new PageContent();
        fixedDocument.Pages.Add(pageContent1);
        FixedPage page1 = new FixedPage();
        // PageContent : some text or an object can be added
        ((IAddChild)pageContent1).AddChild(page1);

        MapDrawingElement elt = new MapDrawingElement();
        page1.Children.Add(elt);
        return fixedDocument;
    }
}

然后就可以打印了:

    PrintDocumentImageableArea imageArea = null;
    XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(ref imageArea);
    if (xpsdw != null)
    {
        xpsdw.Write(DocumentMaker.GenerateFixedDocument());
    }

您还可以打印预览或发送到 XPS 文件。

查看链接中的工作演示:

http://1drv.ms/1RefeuJ

问候

【讨论】:

    猜你喜欢
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多