Problem description:
There are three nsmutable arrays in IOS. How can I use printer to print data similar to the following?
Example:
[Plain]
0.5 1 10
1 10 11
2 5 22
3 4 6
0.5 1 10
1 10 11
2 5 22
3 4 6
Solution:
Use UIPrintInteractionController to implement:
Code:
[Plain]
NSMutableString * stringToPrint = [[NSMutableString alloc] initWithString: @ ""];
For (int I = 0; I <[array count]; I ++)
{
[StringToPrint appendFormat: @ "% @", [array objectAtIndex: I];
If (I % 2 = 0)
{
[StringToPrint appendFormat: @ "\ n"];
}
Else
{
[StringToPrint appendFormat: @ "\ t"];
}
}
UIPrintInteractionController * pic = [UIPrintInteractionController sharedPrintController];
UIPrintInfo * printInfo = [UIPrintInfo printInfo];
PrintInfo. outputType = UIPrintInfoOutputGeneral;
PrintInfo. jobName = @ "Midhun ";
Pic. printInfo = printInfo;
UISimpleTextPrintFormatter * textFormatter = [UISimpleTextPrintFormatter alloc]
InitWithText: stringToPrint];
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 cocould 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];
}
NSMutableString * stringToPrint = [[NSMutableString alloc] initWithString: @ ""];
For (int I = 0; I <[array count]; I ++)
{
[StringToPrint appendFormat: @ "% @", [array objectAtIndex: I];
If (I % 2 = 0)
{
[StringToPrint appendFormat: @ "\ n"];
}
Else
{
[StringToPrint appendFormat: @ "\ t"];
}
}
UIPrintInteractionController * pic = [UIPrintInteractionController sharedPrintController];
UIPrintInfo * printInfo = [UIPrintInfo printInfo];
PrintInfo. outputType = UIPrintInfoOutputGeneral;
PrintInfo. jobName = @ "Midhun ";
Pic. printInfo = printInfo;
UISimpleTextPrintFormatter * textFormatter = [UISimpleTextPrintFormatter alloc]
InitWithText: stringToPrint];
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 cocould 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];
}