Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Pass PDF as Input to Printer
    primarykey
    data
    text
    <p>I m New to the iPhone development and i need to print UIView. so i converted UIView into PDF and it work fine for me.. but i don't know how to pass this PDF to Printer so that it print, can any one help in solving this</p> <p>Thanks in advance </p> <p>my code is:</p> <pre><code>- (void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename { NSMutableData *pdfData = [NSMutableData data]; UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil); UIGraphicsBeginPDFPage(); CGContextRef pdfContext = UIGraphicsGetCurrentContext(); [aView.layer renderInContext:pdfContext]; UIGraphicsEndPDFContext(); NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES); NSString* documentDirectory = [documentDirectories objectAtIndex:0]; NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename]; [pdfData writeToFile:documentDirectoryFilename atomically:YES]; NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename); } -(void)getPDF{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *documentsPath = [paths objectAtIndex:0]; NSString *filePath = [documentsPath stringByAppendingPathComponent:@"myPdf"]; NSLog(@"filePath: %@",filePath); NSData *pngData = [NSData dataWithContentsOfFile:filePath]; [displayPDFView loadData:pngData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil]; [self.view setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.0]]; displayPDFView.hidden = NO; } </code></pre> <p>// printer Code</p> <pre><code>NSString *path = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"png"]; NSData *dataFromPath = [NSData dataWithContentsOfFile:path]; UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController]; if(printController &amp;&amp; [UIPrintInteractionController canPrintData:dataFromPath]) { printController.delegate = self; UIPrintInfo *printInfo = [UIPrintInfo printInfo]; printInfo.outputType = UIPrintInfoOutputGeneral; printInfo.jobName = [path lastPathComponent]; printInfo.duplex = UIPrintInfoDuplexLongEdge; printController.printInfo = printInfo; printController.showsPageRange = YES; printController.printingItem = dataFromPath; void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { if (!completed &amp;&amp; error) { NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code); } }; [printController presentFromRect:btnPrint.frame inView:btnPrint.superview animated:YES completionHandler:completionHandler]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload