簡體   English   中英

通過OxyPlot C#將模型繪制到XPS

[英]Plotmodel to XPS via OxyPlot C#


我目前在將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將被刪除,而您只能看到新的Plotmodel。

因此問題是:

我也嘗試使用:

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

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

如果事先知道將多個圖寫入一個文件,則應查看VisualsToXpsDocument

如果確實必須將其他頁面附加到磁盤上的現有文檔中,則將更加困難。 您將需要深入瀏覽現有文檔以找到FixedDocumentFixedDocument的子FixedDocumentSequence )。 獲得FixedDocument ,可以向其添加一個新的PageContent對象。 該線程底部附近有一個示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM