【发布时间】:2015-05-07 06:34:33
【问题描述】:
您好,我们正在尝试创建一个基于 WPF 页眉和页脚元素的自定义模板系统,以及用于导出到 PDF 的 2D 绘图的画布。问题是 XpsWriter 需要大约 7 秒来编写 XPS 文档,另外需要 3 秒才能使用 PDFSharp 转换为 pdf。当用户等待 PDF 时,我们需要把它记下来。我首先怀疑是因为FrameworkElements的数量,但只有5000个。框架元素大多是PATH数据,带有填充、笔触和画笔。
Canvas ComplexCanvas = new Canvas();
ComplexCanvas.Children.Add(5000Elements);
System.Windows.Documents.FixedDocument fixedDoc = new System.Windows.Documents.FixedDocument();
System.Windows.Documents.PageContent pageContent = new System.Windows.Documents.PageContent();
System.Windows.Documents.FixedPage fixedPage = new System.Windows.Documents.FixedPage();
//Create first page of document
fixedPage.Children.Add(ComplexCanvas);
fixedPage.Width = PageWidth;
fixedPage.Height = PageHeight;
((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage);
fixedDoc.Pages.Add(pageContent);
System.Windows.Xps.Packaging.XpsDocument xpsd = new XpsDocument(Path, System.IO.FileAccess.Write);
System.Windows.Xps.XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
xw.Write(fixedDoc);
xpsd.Close();
有人知道加快速度的方法吗?也许某种类型的视觉对象,或以某种方式或任何想法“展平”画布。当它工作时,PDF 超过 5MB。
希望尽可能保留 VECTOR
【问题讨论】:
-
我刚刚发现在某些情况下使用透明画笔会导致 PDFSharp 崩溃。我改用了一个空的视觉画笔。仅此一项就导致额外的 5 秒
-
事实证明 SolidColorBrush("Color") 使用的资源比“Brush.Color”多。使用 Brush.Color 转换为 XPS 需要额外 5 秒
标签: c# wpf pdfsharp xps xpsdocument