1


我目前面临将 Plotmodel 打印到 XPS 文件的问题。

到目前为止我所拥有的:


/// <summary>
/// Plotmodel to XPS-File
/// </summary>
/// <param name="model">The model</param>
/// <param name="fileName">The fileName</param>
/// <param name="width">Width of the model</param>
/// <param name="height">Height of the model</param>
public void Export(PlotModel model, string fileName, double width, double height)
{
   try
   {
      using (Package xpsPackage = Package.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
      {
        using (var doc = new XpsDocument(xpsPackage))
        {
            var g = new Grid();

            var p = new OxyPlot.Wpf.Plot { Model = model }; //Problem?
            g.Children.Add(p);

            var size = new Size(width, height);
            g.Measure(size);
            g.Arrange(new Rect(size));
            g.UpdateLayout();


            if (xpsdw == null) //XpsDocumentWriter xpsdw
                xpsdw = XpsDocument.CreateXpsDocumentWriter(doc);
            }
            if (xpsdw != null)
            {
                xpsdw.Write(g);
            }
        }
    }
}

此代码工作正常(一次),但问题是:无论您多久使用此方法,您将始终只有一个包含数据的页面。因此,如果您想将第二个 Plotmodel 打印到 XPS 文件中,旧的将被删除,您只能看到新的。

所以问题是: 你有一个想法,如何将新的 Plotmodel 附加到旧的 XPS 文件而不覆盖它?

我也尝试使用:

XpsExporter.Export(model, fileName, width, height);

而不是我的功能,但这也不起作用。

4

1 回答 1

0

如果您事先知道要将多个绘图写入单个文件,则应查看VisualsToXpsDocument

如果您确实必须将其他页面附加到磁盘上的现有文档,那将更加困难。您将需要深入挖掘现有文档以找到FixedDocument( 的子级FixedDocumentSequence)。拥有 后FixedDocument,您可以向其添加新PageContent对象。在该线程的底部附近有一个示例。

于 2014-01-08T15:52:12.743 回答