private void cmdShowAllAnotations_Click(object sender, RoutedEventArgs e) { IList <Annotation> annotations = service.Store.GetAnnotations(); foreach (Annotation annotation in annotations) { // Check for text information. if (annotation.Cargos.Count > 1) { string base64Text = annotation.Cargos[1].Contents[0].InnerText; byte[] decoded = Convert.FromBase64String(base64Text); MemoryStream m = new MemoryStream(); m.Write(decoded, 0, decoded.Length); m.Position = 0; StreamReader r = new StreamReader(m); string annotationXaml = r.ReadToEnd(); MessageBox.Show(annotationXaml); } } PrintDialog dialog = new PrintDialog(); bool? result = dialog.ShowDialog(); if (result != null && result.Value) { System.Windows.Xps.XpsDocumentWriter writer = System.Printing.PrintQueue.CreateXpsDocumentWriter(dialog.PrintQueue); AnnotationDocumentPaginator adp = new AnnotationDocumentPaginator( ((IDocumentPaginatorSource)docReader.Document).DocumentPaginator, service.Store); writer.Write(adp); } }
//Handles the click of the print button in the document //viewer, overriding the default behavior. private void DocumentViewer_PrintDocument(object sender, RoutedEventArgs e) { //Get a print queue PrintQueue printQueue = ShowPrintDialog(); if (printQueue == null) { return; } try { //Create a new XPS writer using the chosen print queue. XpsDocumentWriter writer = PrintQueue.CreateXpsDocumentWriter(printQueue); //We need to use a copy of the document's fixed document //sequence when creating the AnnotationDocumentPaginator. FixedDocumentSequence fds = xpsDocument.GetFixedDocumentSequence(); //You now need to create a document paginator for any //annotations in the document. AnnotationDocumentPaginator adp = new AnnotationDocumentPaginator(fds.DocumentPaginator, fixedAnnotationService.Store); //Write out the document, with annotations using the annotation //document paginator. writer.Write(adp); } catch (Exception ex) { MessageBox.Show(ex.Message); } }