コード例 #1
0
        private void BtnPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog dialog = new PrintDialog();

            if (!dialog.ShowDialog() ?? true)
            {
                return;
            }
            var sz       = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);
            var document = new FixedDocument();

            document.DocumentPaginator.PageSize = sz;
            for (int c = 1; c <= page.PgCount; c++)
            {
                var p = new FormPage(page.Data, page.Imgs, sz, page.Lang, false)
                {
                    ImgSize  = page.ImgSize,
                    TextSize = page.TextSize
                };
                if (c == page.PgCount)
                {
                    p.DoFirmas();
                }
                p.GotoPage(c);
                p.ShowPager(c, page.PgCount);
                p.Measure(sz);
                p.Arrange(new Rect(sz));
                p.UpdateLayout();
                p.FdpwContent.UpdateLayout();
                if (c == page.PgCount)
                {
                    MessageBox.Show("Imprimiendo documento...", "Imprimir", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                Grid pc = p.RootContent;
                p.Content = null;
                p         = null;
                pc.Measure(sz);
                pc.Arrange(new Rect(sz));
                pc.UpdateLayout();
                var fixedPage = new FixedPage
                {
                    Width  = sz.Width,
                    Height = sz.Height
                };
                fixedPage.Children.Add(pc);
                var pageContent = new PageContent();
                ((IAddChild)pageContent).AddChild(fixedPage);
                document.Pages.Add(pageContent);
            }
            dialog.PrintDocument(document.DocumentPaginator, $"Biopsia {page.TxtBiop.Text}");
        }