Print an additional UIMarkupTextPrintFormatter page

When using UIMarkupTextPrintFormatter to print multiple lines of plain HTML, a blank page is displayed first, and then a page with text. The code is as follows and very simple:

- (void) printSomething; { if (![UIPrintInteractionController isPrintingAvailable]) return; NSString* markupText =@"<html><body>THIS IS A TEST</body></html>"; UIMarkupTextPrintFormatter* printFormatter =[ [ [UIMarkupTextPrintFormatter alloc] initWithMarkupText:markupText] autorelease]; UIPrintInteractionController* printInteractionController =[UIPrintInteractionController sharedPrintController]; printInteractionController.printFormatter =printFormatter; printInteractionController.delegate =self; //printInteractionController.showsPageRange =YES; [printInteractionController presentAnimated:YES completionHandler:nil]; } 

Now, if I uncomment it shows PageRange = YES , one page prints as expected, BUT the UIPrintInteractionController takes a few seconds. It is enough for the user to wonder if the application is frozen.

The very first line of the UIMarkupTextPrintFormatter document says, " Instances of the UIMarkupTextPrintFormatter class contain HTML markup text for multi-page printing jobs ." It would be insanely insane if the formatter prints multiple pages, regardless of content ...

Any idea what's wrong here? Other applications do this without any problems. Thanks in advance.

+8
ios printing
source share
3 answers

I solved this with the correct HTML skeleton:

 NSString *htmlString = "<!DOCTYPE html><html><head><meta charset='UTF-8'><title>Title</title></head><body>Hello!</body></html>" 
+6
source share

I had the same problem with the appearance of a second blank page with printInteractionController.showsPageRange = NO; and found an example of Apple here (p. 67). Here he is:

 - (IBAction)printContent:(id)sender { UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController]; pic.delegate = self; UIPrintInfo *printInfo = [UIPrintInfo printInfo]; printInfo.outputType = UIPrintInfoOutputGeneral; printInfo.jobName = self.documentName; pic.printInfo = printInfo; UIMarkupTextPrintFormatter *htmlFormatter = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:self.htmlString]; htmlFormatter.startPage = 0; htmlFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1 inch margins pic.printFormatter = htmlFormatter; pic.showsPageRange = YES; void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { if (!completed && error) { NSLog(@"Printing could not complete because of error: %@", error); } }; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { [pic presentFromBarButtonItem:sender animated:YES completionHandler:completionHandler]; } else { [pic presentAnimated:YES completionHandler:completionHandler]; } } 

This example uses printInteractionController.showsPageRange = YES; and it works fine, but if you replace this line with

printInteractionController.showsPageRange = NO; , it prints an extra second blank page.

So, it seems that UIMarkupTextPrintFormatter implicitly supposed to be used with printInteractionController.showsPageRange = YES; , or is it just an API error.

+4
source share

I have the same problem and I found out that this is caused by html code

 style='page-break-after:always; 
0
source share

All Articles