I am using iOs default PrinterToPrint in Xamarin to print without showing dialog to choose printer but then also it's showing one dialog which says printing to [PRINTER NAME]. Is there anyway to hide the dialog as well. Like complete silent print functionality?
我在Xamarin中使用iOs默认的PrinterToPrint进行打印而没有显示选择打印机的对话框,但是它还显示了一个对话框,表示打印到[PRINTER NAME]。反正也有隐藏对话框。像完整的静音打印功能?
I am not its possible but I have seen some apps which do that and I am not sure whether they are using the same function or not.
我不是可能的,但我看到一些应用程序这样做,我不确定他们是否使用相同的功能。
Thanks in advance.
提前致谢。
1 个解决方案
#1
2
Update:
UIPrinterPickerController
comes from UIKit
and as such there is no way to push the "printing" process to the background and off the main UI thread.
UIPrinterPickerController来自UIKit,因此没有办法将“打印”过程推送到后台和主UI线程。
In the current UIPrintInteractionController.PrintToPrinter
implementation (currently up to iOS 10.3 B4) there is no exposed way to disable the print progress (Connecting, Preparing, etc...) alart/dialog (w/ Cancel button) or to modify its appearance.
在当前的UIPrintInteractionController.PrintToPrinter实现中(目前达到iOS 10.3 B4),没有公开的方法来禁用打印进度(连接,准备等...)alart / dialog(带取消按钮)或修改其外观。
This interface is high level wrapper using AirPrint
and thus Internet Print Protocol (IPP) at a lower level to preform the actual printing, job queue monitoring on the printer, etc... IPP is not currently exposed as a publicly available framework within iOS...
此接口是使用AirPrint的高级包装器,因此是较低级别的Internet打印协议(IPP),用于执行打印机上的实际打印,作业队列监控等... IPP目前未作为iOS中公开可用的框架公开。 ..
Programs that allow background printing are not using UIPrintInteractionController
to do the printing. Most do use UIPrinterPickerController
to obtain a UIPrinter
selection from the user, but then use the UIPrinter.Url.AbsoluteUrl
to "talk" directly to the printer via HTTP/HTTPS Post/Get. Depending upon the printers used, TCP-based sockets are also an option vs. IPP and even USB/serial for direct connected printers.
允许后台打印的程序不使用UIPrintInteractionController进行打印。大多数人都使用UIPrinterPickerController从用户那里获取UIPrinter选择,然后使用UIPrinter.Url.AbsoluteUrl通过HTTP / HTTPS Post / Get直接与打印机“对话”。根据所使用的打印机,基于TCP的套接字也是IPP的选项,甚至是直接连接打印机的USB /串行选项。
Re: https://en.wikipedia.org/wiki/Internet_Printing_Protocol
回复:https://en.wikipedia.org/wiki/Internet_Printing_Protocol
Original:
Pick a Printer:
选择一台打印机:
if (allowUserToSelectDifferentPrinter || printerUrl == null)
{
UIPrinter uiPrinter = printerUrl != null ? null as UIPrinter : UIPrinter.FromUrl(new NSUrl(printerUrl));
var uiPrinterPickerController = UIPrinterPickerController.FromPrinter(uiPrinter);
uiPrinterPickerController.Present(true, (printerPickerController, userDidSelect, error) =>
{
if (userDidSelect)
{
uiPrinter = uiPrinterPickerController?.SelectedPrinter;
printerUrl = uiPrinter.Url.AbsoluteUrl.ToString();
Console.WriteLine($"Save this UIPrinter's Url string for later use: {printerUrl}");
}
});
}
Print using UIPrintInteractionController
with an existing UIPrinter
:
使用UIPrintInteractionController与现有UIPrinter打印:
if (printerUrl != null)
{
// re-create a UIPrinter from a saved NSUrl string
var uiPrinter = UIPrinter.FromUrl(new NSUrl(printerUrl));
var printer = UIPrintInteractionController.SharedPrintController;
printer.ShowsPageRange = false;
printer.ShowsNumberOfCopies = false;
printer.ShowsPaperSelectionForLoadedPapers = false;
var printInfo = UIPrintInfo.PrintInfo;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "* Print Job";
var textFormatter = new UISimpleTextPrintFormatter("* Rocks")
{
StartPage = 0,
ContentInsets = new UIEdgeInsets(72, 72, 72, 72),
MaximumContentWidth = 6 * 72,
};
printer.Delegate = new PrintInteractionControllerDelegate();
printer.PrintFormatter = textFormatter;
printer.PrintToPrinter(uiPrinter, (printInteractionController, completed, error) =>
{
if ((completed && error != null))
{
Console.WriteLine($"Print Error: {error.Code}:{error.Description}");
PresentViewController(
UIAlertController.Create("Print Error", "Code: {error.Code} Description: {error.Description}", UIAlertControllerStyle.ActionSheet),
true, () => { });
}
printInfo?.Dispose();
uiPrinter?.Dispose();
uiPrinter.
});
}
else
{
Console.WriteLine("User has not selected a printer...printing disabled");
}
#1
2
Update:
UIPrinterPickerController
comes from UIKit
and as such there is no way to push the "printing" process to the background and off the main UI thread.
UIPrinterPickerController来自UIKit,因此没有办法将“打印”过程推送到后台和主UI线程。
In the current UIPrintInteractionController.PrintToPrinter
implementation (currently up to iOS 10.3 B4) there is no exposed way to disable the print progress (Connecting, Preparing, etc...) alart/dialog (w/ Cancel button) or to modify its appearance.
在当前的UIPrintInteractionController.PrintToPrinter实现中(目前达到iOS 10.3 B4),没有公开的方法来禁用打印进度(连接,准备等...)alart / dialog(带取消按钮)或修改其外观。
This interface is high level wrapper using AirPrint
and thus Internet Print Protocol (IPP) at a lower level to preform the actual printing, job queue monitoring on the printer, etc... IPP is not currently exposed as a publicly available framework within iOS...
此接口是使用AirPrint的高级包装器,因此是较低级别的Internet打印协议(IPP),用于执行打印机上的实际打印,作业队列监控等... IPP目前未作为iOS中公开可用的框架公开。 ..
Programs that allow background printing are not using UIPrintInteractionController
to do the printing. Most do use UIPrinterPickerController
to obtain a UIPrinter
selection from the user, but then use the UIPrinter.Url.AbsoluteUrl
to "talk" directly to the printer via HTTP/HTTPS Post/Get. Depending upon the printers used, TCP-based sockets are also an option vs. IPP and even USB/serial for direct connected printers.
允许后台打印的程序不使用UIPrintInteractionController进行打印。大多数人都使用UIPrinterPickerController从用户那里获取UIPrinter选择,然后使用UIPrinter.Url.AbsoluteUrl通过HTTP / HTTPS Post / Get直接与打印机“对话”。根据所使用的打印机,基于TCP的套接字也是IPP的选项,甚至是直接连接打印机的USB /串行选项。
Re: https://en.wikipedia.org/wiki/Internet_Printing_Protocol
回复:https://en.wikipedia.org/wiki/Internet_Printing_Protocol
Original:
Pick a Printer:
选择一台打印机:
if (allowUserToSelectDifferentPrinter || printerUrl == null)
{
UIPrinter uiPrinter = printerUrl != null ? null as UIPrinter : UIPrinter.FromUrl(new NSUrl(printerUrl));
var uiPrinterPickerController = UIPrinterPickerController.FromPrinter(uiPrinter);
uiPrinterPickerController.Present(true, (printerPickerController, userDidSelect, error) =>
{
if (userDidSelect)
{
uiPrinter = uiPrinterPickerController?.SelectedPrinter;
printerUrl = uiPrinter.Url.AbsoluteUrl.ToString();
Console.WriteLine($"Save this UIPrinter's Url string for later use: {printerUrl}");
}
});
}
Print using UIPrintInteractionController
with an existing UIPrinter
:
使用UIPrintInteractionController与现有UIPrinter打印:
if (printerUrl != null)
{
// re-create a UIPrinter from a saved NSUrl string
var uiPrinter = UIPrinter.FromUrl(new NSUrl(printerUrl));
var printer = UIPrintInteractionController.SharedPrintController;
printer.ShowsPageRange = false;
printer.ShowsNumberOfCopies = false;
printer.ShowsPaperSelectionForLoadedPapers = false;
var printInfo = UIPrintInfo.PrintInfo;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "* Print Job";
var textFormatter = new UISimpleTextPrintFormatter("* Rocks")
{
StartPage = 0,
ContentInsets = new UIEdgeInsets(72, 72, 72, 72),
MaximumContentWidth = 6 * 72,
};
printer.Delegate = new PrintInteractionControllerDelegate();
printer.PrintFormatter = textFormatter;
printer.PrintToPrinter(uiPrinter, (printInteractionController, completed, error) =>
{
if ((completed && error != null))
{
Console.WriteLine($"Print Error: {error.Code}:{error.Description}");
PresentViewController(
UIAlertController.Create("Print Error", "Code: {error.Code} Description: {error.Description}", UIAlertControllerStyle.ActionSheet),
true, () => { });
}
printInfo?.Dispose();
uiPrinter?.Dispose();
uiPrinter.
});
}
else
{
Console.WriteLine("User has not selected a printer...printing disabled");
}