在UWP中打印网格时,适合纸张的宽度和高度

时间:2016-07-30 07:27:37

标签: uwp

我正在开发UWP中的应用,我正在使用网格来处理某些内容。出于某些原因,我需要打印网格的内容,并且我已经编写了代码来执行此操作。

代码是这样的:

    PrintManager printmgr = PrintManager.GetForCurrentView();
    PrintDocument PrintDoc = null;
    PrintTask Task = null;
    private void Printmgr_PrintTaskRequested(PrintManager Sender, PrintTaskRequestedEventArgs args)
    {
        var deferral = args.Request.GetDeferral();
        Task = args.Request.CreatePrintTask("Sari-Tech", OnPrintTaskSourceRequrested);
        Task.Completed += PrintTask_Completed;
        deferral.Complete();
    }
    private void PrintTask_Completed(PrintTask Sender, PrintTaskCompletedEventArgs args)
    {
    }
    private async void OnPrintTaskSourceRequrested(PrintTaskSourceRequestedArgs args)
    {
        var def = args.GetDeferral();
        await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
            () =>
            {
             // Set the print source 
             args.SetSource(PrintDoc?.DocumentSource);
            });
        def.Complete();
    }
    private void PrintDic_AddPages(Object Sender, AddPagesEventArgs e)
    {
            PrintDoc.AddPage(sp_PrintArea);

        // completed to increase the printed page 
        PrintDoc.AddPagesComplete();
    }
    private void OnGetPreviewPage(Object Sender, GetPreviewPageEventArgs e)
    {
            PrintDoc.SetPreviewPage(e.PageNumber, sp_PrintArea);
    }
    private void PrintDic_Paginate(Object Sender, PaginateEventArgs e)
    {
        PrintTaskOptions opt = Task.Options;
        PrintDoc.SetPreviewPageCount(1, PreviewPageCountType.Final);
    }
    async private void PrintGoBTN_Click(object sender, RoutedEventArgs e)
    {
        if (PrintDoc != null)
        {
            PrintDoc.GetPreviewPage -= OnGetPreviewPage;
            PrintDoc.Paginate -= PrintDic_Paginate;
            PrintDoc.AddPages -= PrintDic_AddPages;
        }
        this.PrintDoc = new PrintDocument();

        PrintDoc.GetPreviewPage += OnGetPreviewPage;
        PrintDoc.Paginate += PrintDic_Paginate;
        PrintDoc.AddPages += PrintDic_AddPages;

        bool showPrint = await PrintManager.ShowPrintUIAsync();
    }

现在我希望这些内容完全适合论文。我不知道该怎么做。我试图将网格大小调整到A4纸的大小,但由于大部分内容超出了屏幕大小,因此无法正常工作。

你能帮帮我吗?

0 个答案:

没有答案