android - 适用于 Android 和 iOS 应用程序的静音打印功能
问题描述
我正在使用 Xamarin 开发 iOS 和 Android 应用程序,我正在尝试打印实现静默打印功能,目前我正在使用以下 Android 本机脚本,这些脚本在打印期间始终显示对话框。
使用 Webview 的 Android 打印脚本:
public void Print(WebView viewToPrint)
{
var droidViewToPrint = Platform.CreateRenderer(viewToPrint).ViewGroup.GetChildAt(0) as Android.Webkit.WebView;
if (droidViewToPrint != null)
{
// Only valid for API 19+
var version = Android.OS.Build.VERSION.SdkInt;
if (version >= Android.OS.BuildVersionCodes.Kitkat)
{
var printMgr = (PrintManager)Forms.Context.GetSystemService(Context.PrintService);
printMgr.Print("Forms-EZ-Print", droidViewToPrint.CreatePrintDocumentAdapter(), null);
}
}
}
文本的 iOS 打印脚本:
public void Print()
{
var printInfo = UIPrintInfo.PrintInfo;
printInfo.JobName = "My first Print Job";
printInfo.OutputType = UIPrintInfoOutputType.General;
var textFormatter = new UISimpleTextPrintFormatter("Once upon a time...")
{
StartPage = 0,
MaximumContentWidth = 6 * 72,
PerPageContentInsets = new UIEdgeInsets(72, 72, 72, 72),
};
var printer = UIPrintInteractionController.SharedPrintController;
printer.PrintInfo = printInfo;
printer.PrintFormatter = textFormatter;
printer.ShowsPageRange = true;
printer.Present(true, (handler, completed, error) =>
{
if (!completed && error != null)
{
Console.WriteLine($"Error: {error.LocalizedDescription ?? ""}");
}
});
printInfo.Dispose();
textFormatter.Dispose();
}
请问如何在没有任何打印预览或对话框的情况下从 iOS 和 Android 应用程序静默打印?
解决方案
推荐阅读
- r - 将一列列表转换为data.frame中的常规列?
- docker - 来自主机 Windows 的 docker 中 ubuntu 上的 nvidia 驱动程序支持 - “在您的系统上找不到 NVIDIA 驱动程序”错误
- c# - c# 在没有库的情况下构建图表
- python - 每个月输入12个温度值,显示温度最高的月份数
- python-3.x - 将 pandas df 中的句子拆分为多行单词并对每个句子进行编号
- c# - 如何设置 dotnet 日志记录的文化?
- mysql - MYSQL 连接两个表,但用 table2 值填充 table1
- python-3.x - Django没有拿起功能
- jenkins - Jenkins 将环境传递给 pod 模板
- matlab - 为什么matlab不读取命令ReadData3d?