/// <summary> /// Print the document /// </summary> private void Print() { // We need to build the flowdocument in code behind, otherwise there will be no paging with Lists and UIBlocks.... var flowDocument = new FlowDocument(); flowDocument.PageWidth = 650; flowDocument.PageHeight = 900; var title = new Paragraph(new Run($"{CurrentFortressData.FortressName} emergency sheet") { FontSize = 25 }); var subtitle = new Paragraph(new Run("Category => Name => Username => Password") { FontSize = 12 }); flowDocument.Blocks.Add(title); flowDocument.Blocks.Add(subtitle); var list = new List(); foreach (var printableVm in PrintablePasswordEntries) { var pwEntry = $"{printableVm.Category} - {printableVm.Name} - {printableVm.Username}:{Environment.NewLine}{printableVm.Password}"; var para = new Paragraph(new Run(pwEntry)) { Margin = new System.Windows.Thickness(12, 0, 12, 0) }; list.ListItems.Add(new ListItem(para)); } flowDocument.Blocks.Add(list); // It is crucial, that we create the xps file in memory only and never write it onto the harddrive. var package = Package.Open(new MemoryStream(), FileMode.Create, FileAccess.ReadWrite); var packUri = new Uri("pack://temp.xps"); PackageStore.RemovePackage(packUri); PackageStore.AddPackage(packUri, package); var xpsDocument = new XpsDocument(package, CompressionOption.SuperFast, packUri.ToString()); var paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator; new XpsSerializationManager(new XpsPackagingPolicy(xpsDocument), false) .SaveAsXaml(paginator); Document = xpsDocument.GetFixedDocumentSequence(); // Show the printable Document var printView = new PrintView(Document); printView.DataContext = this; printView.Show(); }
private void btPrint_Click(object sender, EventArgs e) { if (data.GetActiveBack() == null) { MessageBox.Show("No hay ningun estilo de tarjeta activo"); return; } UpdateChoferes(); if (printview == null) { printview = new PrintView(data); } printview.Show(this); printview.LoadData(); }