How to print multiple WPF pages in one document

前端 未结 1 1077
醉梦人生
醉梦人生 2020-12-17 06:09

I want to create a document with several pages and with one wpf window depicted on each page.

I managed to print one window using PrintDialog and PrintVisual. Howeve

相关标签:
1条回答
  • 2020-12-17 06:12

    You want to create a FixedDocument with multiple FixedPages.

    Example:

    How to create a new document and single page.

    var pageSize = new Size(8.26 * 96, 11.69 * 96); // A4 page, at 96 dpi
    var document = new FixedDocument();
    document.DocumentPaginator.PageSize = pageSize;
    
    // Create FixedPage
    var fixedPage = new FixedPage();
    fixedPage.Width = pageSize.Width;
    fixedPage.Height = pageSize.Height;
    // Add visual, measure/arrange page.
    fixedPage.Children.Add((UIElement)visual);
    fixedPage.Measure(pageSize);
    fixedPage.Arrange(new Rect(new Point(), pageSize));
    fixedPage.UpdateLayout();
    
    // Add page to document
    var pageContent = new PageContent();
    ((IAddChild)pageContent).AddChild(fixedPage);
    document.Pages.Add(pageContent);
    
    // Send to the printer.
    var pd = new PrintDialog();
    pd.PrintDocument(document.DocumentPaginator, "My Document");
    

    Written in C#, however you should be able to convert to VB.

    HTH,

    0 讨论(0)
提交回复
热议问题