1

我的 xaml 中有一个 webview,由于 webview 的大小,它不能一次显示所有的 html 内容,所以有一个滚动查看器。我想打印html文件的所有内容,但是当我在设备魅力中选择打印机时,预览页面只显示当前在webview中显示的内容,不可见的内容无法显示在预览页面中,任何人可以帮忙?下面是我的代码。

public sealed partial class MainPage : Page
{
    PrintDocument printDocument;
    IPrintDocumentSource printDocumentSource;
    WebView wv;

    public MainPage()
    {
        this.InitializeComponent();
        printDocument = new PrintDocument();
        printDocumentSource = printDocument.DocumentSource;
        printDocument.Paginate += OnPrintDocumentPaginate;
        printDocument.GetPreviewPage += OnPrintDocumentGetPreviewPage;
        printDocument.AddPages += OnPrintDocumentAddPages;
        wv = FindName("webviewPrint") as WebView;            
    }

    private void OnPrintDocumentAddPages(object sender, AddPagesEventArgs e)
    {
        printDocument.AddPage(wv);
        printDocument.AddPagesComplete();
    }

    private void OnPrintDocumentGetPreviewPage(object sender, GetPreviewPageEventArgs e)
    {
        printDocument.SetPreviewPage(e.PageNumber, wv);
    }

    private void OnPrintDocumentPaginate(object sender, PaginateEventArgs e)
    {
        printDocument.SetPreviewPageCount(1, PreviewPageCountType.Final);            
    }

    private void OnPrintManagerPrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
    {
        args.Request.CreatePrintTask("Hello Printer", OnPrintTaskSourceRequested);

    }

    void OnPrintTaskSourceRequested(PrintTaskSourceRequestedArgs args)
    {
        args.SetSource(printDocumentSource);
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        PrintManager.GetForCurrentView().PrintTaskRequested += OnPrintManagerPrintTaskRequested;
        base.OnNavigatedTo(e);
    }

    protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
    {
        PrintManager.GetForCurrentView().PrintTaskRequested -= OnPrintManagerPrintTaskRequested;
        base.OnNavigatingFrom(e);
    }

}
4

1 回答 1

0

在来自官方 Windows SDK 示例的打印示例中,请查看场景 2。它打印的内容对于一个屏幕来说太大了。该示例使用RichTextBlock,您将在您的情况下将其更改为WebView

于 2013-01-14T18:51:37.427 回答