DocumentViewer / DocumentPaginator - only FixedDocument or FixedDocumentSequence???Hello all,<br/> <br/> when I assign my own DocumentPaginator to the DocumentViewer's Document I get an exception only FixedDocuments or FixedDocumentSequences are allowed.<br/> <br/> I basicly want to modify pages of a XPS document (adding additional text/lines...) and show them in the DocumentViewer. I just thought I create my own DocumentPaginator (implementing also IDocumentPaginatorSource) and return the modified (document)pages in the method GetPage() so the pages getting created on-the-fly when the Document-Viewer needs to load and display them. But it seems this is not possible...<br/> <br/> So the only way I currently see is to create a new XpsDocument in memory (either rendering using XpsSerializationManager/my own DocumentPaginator or via XpsDocumentWriter/SerializerWriterCollator) and then display this new created in the viewer. However I need to render *ALL* pages at once and when having documents with lots of pages this could take some seconds (f.e. in my case a document needs 7-10s) before showing up in the viewer then... ofcourse not really a good way...<br/> <br/> Are there any better ways to display Visuals (-&gt; DocumentPages) in the DocumentViewer and render pages on the fly when they get displayed??<br/> <br/> Can anyone of Microsoft bring some light into this why it's not possible to assign an own DocumentPaginator to the DocumentViewer providing own DocumentPages???<br/> <br/> any ideas are welcome... <br/> <br/> regards from Germany,<br/> Jo© 2009 Microsoft Corporation. All rights reserved.Tue, 24 Nov 2009 09:14:38 Ze3f37f58-5801-4a4c-a584-8c2bb7926c72http://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/e3f37f58-5801-4a4c-a584-8c2bb7926c72#e3f37f58-5801-4a4c-a584-8c2bb7926c72http://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/e3f37f58-5801-4a4c-a584-8c2bb7926c72#e3f37f58-5801-4a4c-a584-8c2bb7926c72Jo0815http://social.msdn.microsoft.com/Profile/en-US/?user=Jo0815DocumentViewer / DocumentPaginator - only FixedDocument or FixedDocumentSequence???Hello all,<br/> <br/> when I assign my own DocumentPaginator to the DocumentViewer's Document I get an exception only FixedDocuments or FixedDocumentSequences are allowed.<br/> <br/> I basicly want to modify pages of a XPS document (adding additional text/lines...) and show them in the DocumentViewer. I just thought I create my own DocumentPaginator (implementing also IDocumentPaginatorSource) and return the modified (document)pages in the method GetPage() so the pages getting created on-the-fly when the Document-Viewer needs to load and display them. But it seems this is not possible...<br/> <br/> So the only way I currently see is to create a new XpsDocument in memory (either rendering using XpsSerializationManager/my own DocumentPaginator or via XpsDocumentWriter/SerializerWriterCollator) and then display this new created in the viewer. However I need to render *ALL* pages at once and when having documents with lots of pages this could take some seconds (f.e. in my case a document needs 7-10s) before showing up in the viewer then... ofcourse not really a good way...<br/> <br/> Are there any better ways to display Visuals (-&gt; DocumentPages) in the DocumentViewer and render pages on the fly when they get displayed??<br/> <br/> Can anyone of Microsoft bring some light into this why it's not possible to assign an own DocumentPaginator to the DocumentViewer providing own DocumentPages???<br/> <br/> any ideas are welcome... <br/> <br/> regards from Germany,<br/> JoMon, 08 Jun 2009 08:33:34 Z2009-06-08T08:36:49Zhttp://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/e3f37f58-5801-4a4c-a584-8c2bb7926c72#64e02a69-0e94-461a-96ae-a7de838f520dhttp://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/e3f37f58-5801-4a4c-a584-8c2bb7926c72#64e02a69-0e94-461a-96ae-a7de838f520dJo0815http://social.msdn.microsoft.com/Profile/en-US/?user=Jo0815DocumentViewer / DocumentPaginator - only FixedDocument or FixedDocumentSequence???Ok, guess I found a good solution which works for Visuals, though the text of the visuals can't be selected, but I guess myself when using a Canvas-object instead of the VisualHost this would work also, but as my internal renderer using visuals that's Ok for me right now...<br/><br/>The trick is to host the &quot;overlay visual&quot; of a page in a UIElement and then add it to the DocumentPage (Visual -&gt; FixedPage) in the GetPageCompleted-event of the FixedDocumentSequences DocumentPaginator... that way it's not needed to create the whole document at once and the pages (plus their overlays) getting loaded when needed... :)<br/><br/>Here's a little sample code for it, maybe it's also useful for others... It just adds text &quot;Page #XX&quot; on bottom to every page of the XPS document.<br/><br/> <pre lang="x-c#">using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows.Controls; using System.Windows.Xps.Packaging; using System.Windows.Documents; using System.Windows.Media; using System.Windows.Forms; using System.IO; using System.Windows; namespace XpsViewer { public partial class Form1 : Form { private DocumentViewer fDocViewer; public Form1() { InitializeComponent(); Initialize(); } private void Initialize() { // Create a DocumentViewer and add it to ElementHost fDocViewer = new DocumentViewer(); elementHost.Child = fDocViewer; // Load a XpsDocument XpsDocument xpsDocument = new XpsDocument(@&quot;D:\Temp\xDOC_Testdokument.xps&quot;, FileAccess.ReadWrite); // Get the FixedDocumentSequence FixedDocumentSequence fseq = xpsDocument.GetFixedDocumentSequence(); // and set the OnGetPageComplete-Event fseq.DocumentPaginator.GetPageCompleted += OnGetPageComplete; // assign the document to the DocumentViewer fDocViewer.Document = fseq; // close Document xpsDocument.Close(); } private void OnGetPageComplete(object sender, GetPageCompletedEventArgs e) { // Leave here when canccelled or an error ocurred if (e.Cancelled || (e.Error != null)) { return; } // Get the fixed page currently displayed FixedPage page = (FixedPage)e.DocumentPage.Visual; // Create a new visual host... toDO: Maybe needs a check here if our VisualHost is already added to the page??? VisualHost host = new VisualHost(); // ...and add our test-visual host.AddVisual(CreateVisual(page.Width, page.Height, string.Format(&quot;page #{0}&quot;, e.PageNumber + 1))); // add the visual host to the fixed page page.Children.Add(host); } public Visual CreateVisual(double width, double height, string message) { // create a drawing visual DrawingVisual visual = new DrawingVisual(); using (DrawingContext ctx = visual.RenderOpen()) { // just draw some text FormattedText text = new FormattedText(message, System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, new Typeface(&quot;Tahoma&quot;), 12 * 1.5, new SolidColorBrush(Color.FromRgb(0, 0, 0)) ); ctx.DrawText(text, new System.Windows.Point(100, height - 125)); } return visual; } } } </pre> <br/>and here's the class for the VisualHost:<br/><br/> <pre lang="x-c#">public class VisualHost : UIElement { private List&lt;Visual&gt; fVisuals; public VisualHost() { fVisuals = new List&lt;Visual&gt;(); } protected override Visual GetVisualChild(int index) { return fVisuals[index]; } protected override int VisualChildrenCount { get { return fVisuals.Count; } } public void AddVisual(Visual visual) { fVisuals.Add(visual); base.AddVisualChild(visual); } public void RemoveVisual(Visual visual) { fVisuals.Remove(visual); base.RemoveVisualChild(visual); } }</pre> <br/>hope you like it and maybe it's useful... <br/><br/>regards from Germany<br/>JoMon, 08 Jun 2009 16:55:24 Z2009-06-09T06:22:50Zhttp://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/e3f37f58-5801-4a4c-a584-8c2bb7926c72#7ad52a85-a414-4162-898f-964bb47a8d40http://social.msdn.microsoft.com/Forums/en-US/windowsxps/thread/e3f37f58-5801-4a4c-a584-8c2bb7926c72#7ad52a85-a414-4162-898f-964bb47a8d40Jo0815http://social.msdn.microsoft.com/Profile/en-US/?user=Jo0815DocumentViewer / DocumentPaginator - only FixedDocument or FixedDocumentSequence???When I try to add the visual host on first position to get some kind of &quot;watermark&quot; which is behind the original document, <br/> <br/> <pre lang="x-c#">private void OnGetPageComplete(object sender, GetPageCompletedEventArgs e) { ... // set background transparent of original document page.Background = System.Windows.Media.Brushes.Transparent; // insert the visual host to the page on first position page.Children.Insert(0, host); } </pre> <br/> then it displays the text behind, but I'll get the following ArgumentNullException as soon as I move mouse over the documentviewer-control:<br/> <br/> <br/> System.ArgumentNullException wurde nicht behandelt.<br/>   Message=&quot;Der Wert darf nicht NULL sein.\r\nParametername: descendant&quot;<br/>   Source=&quot;PresentationCore&quot;<br/>   ParamName=&quot;descendant&quot;<br/>   StackTrace:<br/>        bei System.Windows.Media.Visual.TransformToDescendant(Visual descendant)<br/>        bei System.Windows.Documents.FixedTextView._SnapToText(Point point)<br/>        bei System.Windows.Documents.FixedTextView.GetTextPositionFromPoint(Point point, Boolean snapToText)<br/>        bei MS.Internal.Documents.TextViewBase.System.Windows.Documents.ITextView.GetTextPositionFromPoint(Point point, Boolean snapToText)<br/>        bei System.Windows.Documents.DocumentSequenceTextView.GetTextPositionFromPoint(Point point, Boolean snapToText)<br/>        bei MS.Internal.Documents.TextViewBase.System.Windows.Documents.ITextView.GetTextPositionFromPoint(Point point, Boolean snapToText)<br/>        bei MS.Internal.Documents.DocumentPageTextView.GetTextPositionFromPoint(Point point, Boolean snapToText)<br/>        bei MS.Internal.Documents.MultiPageTextView.GetTextPositionFromPoint(Point point, Boolean snapToText)<br/>        bei MS.Internal.Documents.TextViewBase.System.Windows.Documents.ITextView.GetTextPositionFromPoint(Point point, Boolean snapToText)<br/>        bei System.Windows.Documents.TextEditorMouse.IsPointWithinInteractiveArea(TextEditor textEditor, Point point)<br/>        bei System.Windows.Documents.TextEditorMouse.OnQueryCursor(Object sender, QueryCursorEventArgs e)<br/>        bei System.Windows.Input.QueryCursorEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)<br/>        bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)<br/>        bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)<br/>        bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)<br/>        bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)<br/>        bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)<br/>        bei System.Windows.Input.InputManager.ProcessStagingArea()<br/>        bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)<br/>        bei System.Windows.Input.MouseDevice.UpdateCursorPrivate()<br/>        bei System.Windows.Input.MouseDevice.PostProcessInput(Object sender, ProcessInputEventArgs e)<br/>        bei System.Windows.Input.InputManager.ProcessStagingArea()<br/>        bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)<br/>        bei System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)<br/>        bei System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)<br/>        bei System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)<br/>        bei System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)<br/>        bei MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)<br/>        bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)<br/>        bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)<br/>        bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)<br/>        bei System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)<br/>        bei System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)<br/>        bei System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)<br/>        bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)<br/>        bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)<br/>        bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)<br/>        bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)<br/>        bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)<br/>        bei System.Windows.Forms.Application.Run(Form mainForm)<br/> <br/> <br/> <br/> <strong>anyone got a clue why adding the visualhost works, but not when inserting on first position??</strong>Tue, 24 Nov 2009 09:14:38 Z2009-11-24T10:12:40Z