Someone could indicate a tutorial, or sample code explaining how to print a text from a UITextField.
Someone could indicate a tutorial, or sample code explaining how to print a text from a UITextField.
Just check isPrintingAvailable
on UIPrintInteractionController
:
if ([UIPrintInteractionController isPrintingAvailable]){
// Chamar impressão
} else {
// Fazer algo que você julgar interessante
}
UIPrintInteractionController
Access the singleton using [UIPrintInteractionController sharedPrintController]
sharedPrintController = [UIPrintInteractionController sharedPrintController];
Seven printingItem
for the item to be printed, can be of classes NSURL
, NSData
, UIImage
, or ALAsset
Using simple text you can simply do
sharedPrintController.printingItem = [self.myUITextField.text dataUsingEncoding:NSUTF8StringEncoding];
Create a completion handler if you deem it necessary:
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"Erro: %@", error);
}
}
Show:
[sharedPrintController presentFromBarButtonItem:self.rightButton animated:YES completionHandler:completionHandler];
UIPrintInfo
You can set information about the print used to property printInfo
of your controller
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = "Nome do Job";
sharedPrintController.printInfo = printInfo;
UISimpleTextPrintFormatter
UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc] initWithAttributedText:self.myUITextField.attributedText];
textFormatter.startPage = 0;
textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // margens de uma polegada
textFormatter.maximumContentWidth = 6 * 72.0;
sharedPrintController.printFormatter = textFormatter;
sharedPrintController.showsPageRange = YES;
Inspired by: iPhone SDK - simple print file