Hiya guys,
when calling PrintVisual I get an exception, (below):
I'm printing a canvas with the background set to a visualbrush. I've posted some the print code below as well.
Have any of you guys ever seen this exception before? Our code is pretty involved and I can post more or try to get a small application that replicates the problem but I thought I'd post it straight up in case any one's run into it.
The background visual brush is taken from an XPS document. We read the XPS document in and render it to a visual brush which is then saved off as a byte array. The visual brush is then deserialized from the data and turned back into a visualbrush. This code has been working for a long time until Monday there whenever this exception occurs. Every time I do a print the exception occurs when printing a different canvas.
Much appreciated.
Graeme
Exception type: System.NotSupportedException
Specified method is not supported.
Stack trace: at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode, IntPtr errorInfo)
at MS.Internal.Text.TextInterface.Native.Util.ConvertHresultToException(Int32 hr)
at MS.Internal.Text.TextInterface.FontFace.ReadFontEmbeddingRights(UInt16& fsType)
at MS.Internal.FontCache.FontFaceLayoutInfo.get_EmbeddingRights()
at System.Windows.Media.GlyphTypeface.get_EmbeddingRights()
at System.Windows.Xps.Serialization.VisualSerializer.EmbeddingAllowed(GlyphTypeface typeface)
at System.Windows.Xps.Serialization.VisualSerializer.System.Windows.Xps.Serialization.IMetroDrawingContext.DrawGlyphRun(Brush foreground, GlyphRun glyphRun)
at System.Windows.Xps.Serialization.DrawingContextFlattener.DrawGlyphRun(Brush foreground, GlyphRun glyphRun)
at System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(Drawing d, Matrix drawingToWorldTransform)
at System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(Drawing d, Matrix drawingToWorldTransform)
at System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(Drawing d, Matrix drawingToWorldTransform)
at System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(Drawing d, Matrix drawingToWorldTransform)
at System.Windows.Xps.Serialization.VisualSerializer.WriteDrawingBody(Drawing drawing, Matrix worldTransform)
at System.Windows.Xps.Serialization.VisualSerializer.BrushToString(Brush brush, Rect bounds)
at System.Windows.Xps.Serialization.VisualSerializer.FindBrush(Brush brush, Rect bounds)
at System.Windows.Xps.Serialization.VisualSerializer.WriteBrush(String attribute, Brush brush, Rect bounds)
at System.Windows.Xps.Serialization.VisualSerializer.System.Windows.Xps.Serialization.IMetroDrawingContext.DrawGeometry(Brush brush, Pen pen, Geometry geometry)
at System.Windows.Xps.Serialization.DrawingContextFlattener.DrawGeometry(Brush brush, Pen pen, Geometry geometry)
at System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(Drawing d, Matrix drawingToWorldTransform)
at System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(Drawing d, Matrix drawingToWorldTransform)
at System.Windows.Xps.Serialization.VisualTreeFlattener.StartVisual(Visual visual)
at System.Windows.Xps.Serialization.ReachVisualSerializer.SerializeTree(Visual visual, XmlWriter resWriter, XmlWriter bodyWriter)
at System.Windows.Xps.Serialization.ReachVisualSerializer.SerializeObject(Object serializedObject)
at System.Windows.Xps.Serialization.XpsSerializationManager.SaveAsXaml(Object serializedObject)
at System.Windows.Xps.XpsDocumentWriter.SaveAsXaml(Object serializedObject, Boolean isSync)
at System.Windows.Xps.XpsDocumentWriter.Write(Visual visual)
at System.Windows.Controls.PrintDialog.PrintVisual(Visual visual, String description)
at ApplicationLauncher.Client.WpfPrintManager2.PrintPage(PrintArrangementPM arrangement, DocumentPageMapperPM page) in C:\Build\Working.test\Eclipse3\Client Projects\ApplicationLauncher.Client\WpfPrintManager2.cs:line 662
at ApplicationLauncher.Client.WpfPrintManager2.PrintDocument(PrintArrangementPM arrangement, DocumentDTO documentDTO, Int32 extraCopies, String[] pageNames, EclipseServiceManager serviceManager, List`1 watermarks) in C:\Build\Working.test\Eclipse3\Client
Projects\ApplicationLauncher.Client\WpfPrintManager2.cs:line 812
at ApplicationLauncher.Client.WpfPrintManager2.PrintDocument(PrintArrangementPM arrangement, DocumentPM document, Int32 extraCopies, String[] pageNames, EclipseServiceManager serviceManager, List`1 watermarks) in C:\Build\Working.test\Eclipse3\Client
Projects\ApplicationLauncher.Client\WpfPrintManager2.cs:line 730
at ApplicationLauncher.Client.WpfPrintManager2.PrintLocalDocument(PrintArrangementPM arrangement, DocumentPM document, Int32 extraCopies, String[] pageNames, List`1 watermarks) in C:\Build\Working.test\Eclipse3\Client Projects\ApplicationLauncher.Client\WpfPrintManager2.cs:line
1064
at ApplicationLauncher.Client.WpfPrintManager2.PrintLocalDraft(PrintArrangementPM arrangement, DocumentPM document, List`1 watermarks) in C:\Build\Working.test\Eclipse3\Client Projects\ApplicationLauncher.Client\WpfPrintManager2.cs:line 310
at ApplicationLauncher.Client.WpfPrintManager2.PrintDraft(PrintArrangementPM arrangement, Boolean arrangementPrint, Object parentWindow, DocumentPM document, Boolean showTrainingWatermark) in C:\Build\Working.test\Eclipse3\Client Projects\ApplicationLauncher.Client\WpfPrintManager2.cs:line
1039
at ApplicationLauncher.Client.EclipseClient.DocumentWindows.FullDocumentWindow.OnPrintDraftClicked(Object sender, RoutedEventArgs e) in C:\Build\Working.test\Eclipse3\Client Projects\ApplicationLauncher.Client\EclipseClient\DocumentWindows\FullDocumentWindow.xaml.cs:line
986
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
************************************************
Here's the code to do the print:
// Initialise a windows Print server
PrintServer printServer = new PrintServer();
// The print queue depends on the printer name
PrintQueue queue = printServer.GetPrintQueue(printProperties.Printer.Name);
/* The WPF Print Dialog class must be created to display the visual representation of
* the page before it can be printed.
*/
PrintDialog dlg = new PrintDialog();
dlg.PrintTicket = queue.DefaultPrintTicket;
dlg.PrintQueue = queue;
// Specify the size and orientation
dlg.PrintTicket.PageOrientation = (PageOrientation)printProperties.Orientation;
// Get the actual page control - this obtains the canvas
WpfDocumentPage documentPage = (WpfDocumentPage)page.GetEclipseControl().FrameworkContent;
// Set the page media size depending on the width and height of the current page
dlg.PrintTicket.PageMediaSize = LookupPrintSize(documentPage);
// Stupid bit of WPF voodoo. This is to prevent the pages printing blank.
documentPage.Measure(new Size(documentPage.Width, documentPage.Height));
documentPage.Arrange(new Rect(new Point(0, 0), new Size(documentPage.Width, documentPage.Height)));
// Print the visual.
dlg.PrintVisual(documentPage, printProperties.JobName);