c# - 我可以添加用于打印的纸张尺寸 (A6)
问题描述
我想打印完整的照片尺寸 A6 10*14 但我的程序没有 A6 尺寸。
如何在我的程序中添加纸张尺寸 A6?
private void Printmgr_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
{
var deferral = args.Request.GetDeferral();
task = args.Request.CreatePrintTask("Print", OnPrintTaskSourceRequrested);
task.Completed += PrintTask_Completed;
task.Options.MediaSize = Windows.Graphics.Printing.PrintMediaSize.IsoA6;
PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(task.Options);
IList<string> displayedOptions = printDetailedOptions.DisplayedOptions;
// Create a new list option
PrintCustomItemListOptionDetails pageFormat = printDetailedOptions.CreateItemListOption("PageContent", "Pictures");
pageFormat.AddItem("PicturesText", "Image And Frame");
pageFormat.AddItem("PicturesOnly", "Pictures only");
// Add the custom option to the option list
displayedOptions.Add("PageContent");
printDetailedOptions.OptionChanged += printDetailedOptions_OptionChanged;
deferral.Complete();
}
解决方案
如果要打印10*14
请设置 MediaSize
为 NorthAmerica10x14
。IsoA6的大小为4.13*5.83
protected override void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e)
{
PrintTask printTask = null;
printTask = e.Request.CreatePrintTask("C# Printing SDK Sample", async sourceRequestedArgs =>
{
printTask.Options.MediaSize = Windows.Graphics.Printing.PrintMediaSize.NorthAmerica10x14;
var deferral = sourceRequestedArgs.GetDeferral();
PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(printTask.Options);
IList<string> displayedOptions = printDetailedOptions.DisplayedOptions;
// Choose the printer options to be shown.
// The order in which the options are appended determines the order in which they appear in the UI
displayedOptions.Clear();
displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Copies);
displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Orientation);
displayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.ColorMode);
// Create a new list option
PrintCustomItemListOptionDetails pageFormat = printDetailedOptions.CreateItemListOption("PageContent", "Pictures");
pageFormat.AddItem("PicturesText", "Pictures and text");
pageFormat.AddItem("PicturesOnly", "Pictures only");
pageFormat.AddItem("TextOnly", "Text only");
// Add the custom option to the option list
displayedOptions.Add("PageContent");
// Create a new toggle option "Show header".
PrintCustomToggleOptionDetails header = printDetailedOptions.CreateToggleOption("Header", "Show header");
// App tells the user some more information about what the feature means.
header.Description = "Display a header on the first page";
// Set the default value
header.TrySetValue(showHeader);
// Add the custom option to the option list
displayedOptions.Add("Header");
// Create a new list option
PrintCustomItemListOptionDetails margins = printDetailedOptions.CreateItemListOption("Margins", "Margins");
margins.AddItem("WideMargins", "Wide", "Each margin is 20% of the paper size", await wideMarginsIconTask);
margins.AddItem("ModerateMargins", "Moderate", "Each margin is 10% of the paper size", await moderateMarginsIconTask);
margins.AddItem("NarrowMargins", "Narrow", "Each margin is 5% of the paper size", await narrowMarginsIconTask);
// The default is ModerateMargins
ApplicationContentMarginTop = 0.1;
ApplicationContentMarginLeft = 0.1;
margins.TrySetValue("ModerateMargins");
// App tells the user some more information about what the feature means.
margins.Description = "The space between the content of your document and the edge of the paper";
// Add the custom option to the option list
displayedOptions.Add("Margins");
printDetailedOptions.OptionChanged += printDetailedOptions_OptionChanged;
// Print Task event handler is invoked when the print job is completed.
printTask.Completed += (s, args) =>
{
// Notify the user when the print operation fails.
if (args.Completion == PrintTaskCompletion.Failed)
{
MainPage.Current.NotifyUser("Failed to print.", NotifyType.ErrorMessage);
}
};
sourceRequestedArgs.SetSource(printDocumentSource);
deferral.Complete();
});
}
更多请参考PrintMediaSize Enum,这是官方代码示例
推荐阅读
- excel - 不同命名表中的间接索引和匹配问题公式
- django - graphene-django 为 DjangoFilterConnectionField 添加附加参数并将其传递给 get_queryset
- c# - 如何使用 linq lamba 表达式通过内部连接进行分组
- javascript - 在反应中存储来自多个选择的值
- haskell - 有没有办法在模式匹配期间绑定存在数据类型的抑制类型变量?
- python - Pandas:具有另一列唯一值索引的新列
- powershell - 启动 docker 容器时防止 Gitlab 添加 -NoProfile 到 PowerShell
- r - 使用for循环将多个图像(3D数组)存储到R中的4D数组中
- jenkins - 如何从Jenkins的工作区获取文件路径
- gitlab - GitLab CI 更改变量