我创建了一个示例代码,用于在Windows 8应用程序中使用C#XAML打印文档。现在,当我打印时,我想要将文档打印90度旋转。
我如何实现这一目标?
以下是我的代码:
/// <summary>
/// PrintDocument is a Xaml object which converts some PrintManager functionality into paradigms
/// which are used in Xaml (eg. callbacks into events with event handlers).
/// </summary>
private PrintDocument printDocument = null;
/// <summary>
/// The print document source
/// </summary>
IPrintDocumentSource printDocumentSource;
/// <summary>
/// This function registers the app for printing with Windows and sets up the necessary event handlers for the print process.
/// </summary>
private void RegisterForPrinting()
{
// Create the PrintDocument.
printDocument = new PrintDocument();
printDocumentSource = printDocument.DocumentSource;
printDocument.AddPages += OnPrintDocumentAddPages;
printDocument.GetPreviewPage += OnPrintDocumentGetPreviewPage;
// Create a PrintManager and add a handler for printing initialization.
PrintManager printMan = PrintManager.GetForCurrentView();
printMan.PrintTaskRequested += PrintTaskRequested;
}
/// <summary>
/// This function unregisters the app for printing with Windows.
/// </summary>
private void UnregisterForPrinting()
{
// Set the instance of the PrintDocument to null.
printDocument = null;
// Remove the handler for printing initialization.
PrintManager printMan = PrintManager.GetForCurrentView();
printMan.PrintTaskRequested -= PrintTaskRequested;
}
/// <summary>
/// This is the event handler for PrintManager.PrintTaskRequested.
/// </summary>
/// <param name="sender">PrintManager</param>
/// <param name="e">PrintTaskRequestedEventArgs </param>
private void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e)
{
PrintTask printTask = e.Request
.CreatePrintTask("Boarding Pass", PrintSourceTaskHandler);
}
/// <summary>
/// Prints the source task handler.
/// </summary>
/// <param name="args">The args.</param>
private void PrintSourceTaskHandler(PrintTaskSourceRequestedArgs args)
{
args.SetSource(printDocumentSource);
}
private void OnPrintDocumentAddPages(object sender, AddPagesEventArgs e)
{
printDocument.AddPage(root);
printDocument.AddPagesComplete();
}
private void OnPrintDocumentGetPreviewPage(object sender, GetPreviewPageEventArgs e)
{
printDocument.SetPreviewPage(e.PageNumber, root);
}
答案 0 :(得分:0)
对于这个问题,我将纸张的默认方向更改为横向,并且可以将打印更改为90度方向。以下是代码中的更改:
/// <summary>
/// This is the event handler for PrintManager.PrintTaskRequested.
/// </summary>
/// <param name="sender">PrintManager</param>
/// <param name="e">PrintTaskRequestedEventArgs </param>
private void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e)
{
PrintTask printTask = e.Request
.CreatePrintTask("Pass", PrintSourceTaskHandler);
printTask.Options.Orientation = PrintOrientation.Landscape;
}