1
Someone could indicate a tutorial, or sample code explaining how to print a text from an Uitextfield.
1
Someone could indicate a tutorial, or sample code explaining how to print a text from an Uitextfield.
2
Just check out isPrintingAvailable
in the 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 to Property printingItem
for the item you are going to print, it may be of the classes NSURL
, NSData
, UIImage
, or ALAsset
Using plain text you can simply do
sharedPrintController.printingItem = [self.myUITextField.text dataUsingEncoding:NSUTF8StringEncoding];
Create a Completion Handler if you feel it is 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 printing 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
Browser other questions tagged ios objective-c printer
You are not signed in. Login or sign up in order to post.
at the beginning, have a check if it is possible to print. In this case, what can make the printing impossible? That is, what can do the
if ([UIPrintInteractionController isPrintingAvailable])
returnNO
?– Tiago Amaral
TIP: Hardware test kit for Xcode: https://developer.apple.com/downloads/index.action?name=hardware%20io%20tools#
– Tiago Amaral