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);
}