Hello We are trying to create a custom template system based such as WPF Header and Footer elements, with a canvas for 2D Drawings for export to PDF. The problem is the XpsWriter takes about 7 seconds to write the XPS Document, and another 3 Seconds to convert to pdf with PDFSharp. We need to get this down as the user waits for the PDF. I first suspected its due to the number of FrameworkElements in the, but there are only 5000. The framework elements are mostly PATH data with fills, strokes, and brushes.
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();
Does anyone know a way to speed this up? Perhaps some type Visual Object, or "Flatten" the Canvas somehow or any ideas. When it does work the PDF is over 5MB.
Would like to keep it VECTOR as much as possible