我正在打印UIImage
使用AirPrint,但边距不正确.这是打印时的样子:
有没有办法让它完美贴合在纸上?
这是所要求的代码:
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
//pic.delegate = del;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [NSString stringWithFormat:@"New Ticket"];
pic.printInfo = printInfo;
pic.printingItem = [UIImage imageWithContentsOfFile:path];
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error."
message:[NSString stringWithFormat:@"An error occured while printing: %@", error]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[av show];
[av release];
}
};
[pic presentAnimated:YES completionHandler:completionHandler];
Run Code Online (Sandbox Code Playgroud) 在我的iOS应用程序中,我有以下代码用于AirPrinting一个简单的NSString.
#pragma mark - Print
-(IBAction)print:(id)sender {
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"Message";
pic.printInfo = printInfo;
UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc]initWithText:self.Message.text];
textFormatter.startPage = 0;
textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1 inch margins
textFormatter.maximumContentWidth = 6 * 72.0;
pic.printFormatter = textFormatter;
pic.showsPageRange = YES;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"Printing could not …
Run Code Online (Sandbox Code Playgroud) 我有UIPrintInteractionController的问题我发送pdf打印和使用带有ios 5的设备当我按下打印按钮将文件发送到打印机并工作.但是当我在带有ios 6的设备上测试时,我无法工作并使应用程序崩溃.
当ios 6上显示UIPrintInteractionController的视图时,这是日志:
Save\032in\032folder\032Aptana\032Rubles._ipp._tcp.local.:
Get-Printer-Attributes failed: Undefined error: 0
No document-format-supported attribute found or no supported formats
found.
No media-col-database found in response from printer.
Defaulting to generic media size values.
No print-quality-supported attribute found. Defaulting to normal
quality.
No sides-supported attribute found. Defaulting to single-sided.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:(self.myPDF是一个NMutableSData类型)
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
if (controller && [UIPrintInteractionController canPrintData: self.myPDF] ) {
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [NSString stringWithFormat:@"Coupon"];
printInfo.orientation = UIPrintInfoOrientationPortrait;
printInfo.duplex = UIPrintInfoDuplexLongEdge; …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用Safari Webview的混合HTML5/iOS应用程序.我们使用AirPrint允许用户打印webview的内容.我遇到的问题是打开打印对话框后,打印样式会在屏幕上生效,即使打印完成或取消后也不会消失.这不会发生在我们的Windows或Android版本的应用程序中,它们分别使用CEF和Android System Webview.这些版本的应用程序中的打印样式仅应用于打印输出,如预期的那样.
任何人都有使用AirPrint和Safari Webview的经验,可以解释一下解决方案吗?我已经考虑过在打印之前和之后添加/删除包含CSS的链接标签,但是感觉很麻烦,并且没有回答为什么打印样式应用于屏幕的奇怪问题.
任何帮助赞赏!对不起,没有真正的方法来附加代码!
我真的遇到了这个问题.我不知道出了什么问题,但它吐了出来:
错误:尝试显示没有打印源(项目/项目/格式化程序/渲染器)的打印选项
如果我将其设置为打印png图像,而不是NSString的内容,则代码可以正常工作.
这是我的代码:
- (IBAction)pushPrint:(id)sender {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
[dateFormatter setDateFormat:@"dd/MM/YY HH:mm:ss"];
NSString* currentTime = [dateFormatter stringFromDate:[NSDate date]];
[dateFormatter release];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *path = [[NSBundle mainBundle] pathForResource:t[NSString stringWithFormat:@"Results Printout\n"
"\n"
"%@\n"
"\n"
"\n"
"%@", currentTime, pasteboard.string] ofType:nil];
NSData *myData = [NSData dataWithContentsOfFile:path];
UIPrintInteractionController *print = [UIPrintInteractionController sharedPrintController];
print.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [path lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
print.printInfo = printInfo; …
Run Code Online (Sandbox Code Playgroud) 我有一个单例弹出窗口,因此一次只能显示一个弹出窗口。当我执行共享弹出框并选择“ AirPrint”时,共享弹出框会正确消失,并在其位置显示AirPrint弹出框。
但是,如果我再次按下共享按钮,则共享弹出窗口会显示在AirPrint弹出窗口的顶部。
我找不到引用AirPrint弹出窗口将其关闭的方法。
一些进一步的信息-我在屏幕底部的工具栏上有UIBarButtonItems,在屏幕顶部的NavigationBar的rightBarButtonItem中嵌套了四个UIBarButtonItems。
屏幕底部的UIBarButtonItems可以自动正确关闭AirPrint弹出窗口,但顶部的嵌套窗口则不会。
但是,如果我知道AirPrint弹出框的名称,则可以将其从顶部按钮的代码中删除。
尝试使用打印包含表格的html页面UIMarkupTextPrintFormatter
.出于某些奇怪的原因,当第一页上有足够的空间(2-3英寸)时,最后一行被推到第二页.更糟糕的是,当我从html表中删除最后一行时,现在的最后一行(比删除的一行长几英寸)在第1页和第2页之间分开,当它在删除行之前明显适合第1页时.页眉和页脚高度都设置为零.插图也为零.当使用UIWebView并使用打印时,相同的html完全适合1页.
UIViewPrintFormatter *formatter = [webview viewPrintFormatter];
但这需要显示UIWebView(因此它被渲染),我不想这样做.
非常感谢对此的任何见解.
我正在尝试通过iPad应用程序设置打印,单击"打印"将打印包含其所有内容的视图.以下是我尝试过的内容(通过网上的几个例子汇总):
// This is the View I want to print
// Just a 200x200 blue square
var testView = UIView(frame: CGRectMake(0, 0, 200, 200))
testView.backgroundColor = UIColor.blueColor()
let printInfo = UIPrintInfo(dictionary:nil)!
printInfo.outputType = UIPrintInfoOutputType.General
printInfo.jobName = "My Print Job"
// Set up print controller
let printController = UIPrintInteractionController.sharedPrintController()
printController!.printInfo = printInfo
// This is where I was thinking the print job got the
// contents to print to the page??
printController?.printFormatter = testView.viewPrintFormatter()
// Do it
printController!.presentFromRect(self.frame, inView: self, animated: …
Run Code Online (Sandbox Code Playgroud) 为了从工作线程打印到 UIPrinter(我已保存其 URL),我正在执行此操作并能够打印:
func PrintPdfDocument (pDocument:Data)
{
// Create a print interaction controller
let printController = UIPrintInteractionController.shared
// Set the printing options
let printInfo = UIPrintInfo(dictionary:nil)
printInfo.jobName = "Print Job "
printController.printInfo = printInfo
printController.showsPageRange = true
// Set the PDF document to be printed
printController.printingItems = pDocument
printController.print(to: defaulttprinter, completionHandler: { (controller, completed, error) in
if completed {
print("Printing successful!")
} else {
if let error = error {
print("Printing failed with error: \(error.localizedDescription)")
} else {
print("Printing was …
Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码来打印包含文本和图像的HTML内容.
if (![UIPrintInteractionController isPrintingAvailable]) {
UIAlertView *alertView = [[[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Printer Availability Error Title", @"")
message:NSLocalizedString(@"Printer Availability Error Message", @"")
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"OK")
otherButtonTitles:nil] autorelease];
[alertView show];
return;
}
UIPrintInteractionController *pic =
[UIPrintInteractionController sharedPrintController];
if(!pic) {
NSLog(@"Couldn't get shared UIPrintInteractionController!");
return;
}
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"Sample";
pic.printInfo = printInfo;
NSString *htmlString = [self prepareHTMLText];
UIMarkupTextPrintFormatter *htmlFormatter =
[[UIMarkupTextPrintFormatter alloc] initWithMarkupText:htmlString];
htmlFormatter.startPage = 0;
// 1-inch margins on all sides
htmlFormatter.contentInsets …
Run Code Online (Sandbox Code Playgroud)