iOS printing formatting

kevin smith 619

Well-known member
Sep 8, 2010
76
0
0
Visit site
I have been reading through apples printing documentation today to implement it into my app, which is basically a form contained within a scroll view, everything is going just fine however the margins aren't working. Here's my code:

Code:
view plaincopy to clipboardprint?
UIGraphicsBeginImageContext(Frame.frame.size);  
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];  
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();  
UIGraphicsEndImageContext();  
  
UIMarkupTextPrintFormatter *formatter = [[UIMarkupTextPrintFormatter alloc]  
                                             initWithMarkupText:[NSString stringWithFormat:@"%@'s Patient Report", Name.text]];  
formatter.startPage = 0;  
formatter.contentInsets = UIEdgeInsetsMake(142.0, 36.0, 36.0, 36.0);  
  
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];  
controller.delegate = self;  
  
UIPrintInfo *printInfo = [UIPrintInfo printInfo];  
printInfo.outputType = UIPrintInfoOutputGeneral;  
printInfo.jobName = [NSString stringWithFormat:@"%@'s Patient Report", Name.text];  
controller.printInfo = printInfo;  
controller.showsPageRange = YES;  
printInfo.duplex = UIPrintInfoDuplexLongEdge;  
controller.printingItem = viewImage;controller.printFormatter = formatter;  
[formatter release];  
  
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =  
^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {  
    if (!completed && error)  
        NSLog(@"Print failed due to error in domain %@ with error code %u",  
              error.domain, error.code);  
};  
  
[controller presentFromBarButtonItem:printButton animated:YES completionHandler:completionHandler];


All I need really is the picture to be printed below about 2 inches below the top of the paper however when I print it the screen shot fits the page.

Any help is welcomed!
 

KevinMartin

Active member
Sep 7, 2012
42
0
0
Visit site
I got some more code about printing in iOS 4.2 but I am still confused. If anyone solve out my problem.
- (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;

UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc]
initWithText:yourNSStringWithContextOfTextFileHere];
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;
[textFormatter release];
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];
}
}
 

Latest posts

Trending Posts

Members online

Forum statistics

Threads
260,328
Messages
1,766,434
Members
441,237
Latest member
INTERNET BUNDLE NOW