2011-03-25 8 views
7

मैंने इस कोड का उपयोग कर मेल में एक फाइल संलग्न की है।आईफोन या आईपैड पर पीडीएफ फाइल प्रिंट करें

[mail addAttachmentData:[myView PDFData] mimeType:@"application/pdf" fileName:@"name.pdf"]; 

मैं एक फ़ाइल प्रिंट करने के लिए एक ही बात कैसे कर सकते, मैं इस [MyView PDFData] मुद्रित करने के लिए की जरूरत है।

मैं मुद्रण के लिए केवल इस पाया:

NSString *PDFFileWithName = [[NSBundle mainBundle] pathForResource:@"name" ofType:@"pdf"]; 

NSData *dataFromPath = [NSData dataWithContentsOfFile:PDFFileWithName]; 

धन्यवाद

उत्तर

6

आप Drawing and Printing Guide for iOS के माध्यम से पढ़ना चाहिए। printingItemUIPrintInteractionController की संपत्ति को पीडीएफ के NSData पर सेट किया जा सकता है।

जोड़ा कोड

dataFromPath के मूल्य के बराबर होना चाहिए के लिए अद्यतन [MyView PDFData] हालांकि मैं चर नाम बदल रहा है एक बार आप इसे काम कर पाने की सिफारिश करेंगे।

NSData *dataFromPath = [myView PDFData]; 
+0

इन कोड (यह बहुत काम करता है) और कोड मैं ईमेल के लिए उपयोग कर रहा हूँ कर रहे हैं प्रिंटिंग के लिए जो – Marco

+0

बदलना है, मैंने अपना जवाब अपडेट कर दिया है, यदि आप चाहें तो अपने पोस्ट के संपादन में अपना कोड उदाहरण दोबारा पोस्ट कर सकते हैं। – Joe

+1

मैंने इस कोड के साथ किया था, यह वास्तव में आसान था .. सभी को धन्यवाद: printController.printingItem = [myView PDFData]; – Marco

2

पहले गलत लिंक पोस्ट किया गया - यह किसी को मदद करनी चाहिए! नीचे दिए गए कोड

Blog - Printing in iOS - Goes into great detail and includes a tutorial on Printing PDFs

+0

मुझे पता था कि ट्यूटोरियल, यह बहुत अच्छा है, लेकिन मुझे जो चाहिए वह मुझे नहीं मिल रहा है। – Marco

3

लिखने और जाँच यह

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *pathFolder = [NSString stringWithFormat:@"%@",pdfFileName]; 
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:pathFolder]; 
NSURL *targetURL = [NSURL fileURLWithPath:path]; 

UIPrintInteractionController *pc = [UIPrintInteractionController sharedPrintController]; 
UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
printInfo.outputType = UIPrintInfoOutputGeneral; 
printInfo.orientation = UIPrintInfoOrientationPortrait; 
printInfo.jobName [email protected]“Print”; 
printInfo.duplex = UIPrintInfoDuplexLongEdge; 

pc.printInfo = printInfo; 
pc.showsPageRange = YES; 
pc.printingItem = targetURL; 

UIPrintInteractionCompletionHandler completionHandler = 
    ^(UIPrintInteractionController *printController, BOOL completed, 
     NSError *error) { 
    if(!completed && error){ 
     NSLog(@"Print failed - domain: %@ error code %ld", error.domain, (long)error.code); 
    } 
}; 
[pc presentFromRect:shareButton.frame inView:self.view animated:YES completionHandler:completionHandler]; 
+0

क्या आप अपना उत्तर विवरण के साथ विस्तारित कर सकते हैं * क्यों * यह कोड समस्या हल करेगा? वर्णन के बिना एक कोड डंप शायद ही कभी भविष्य के पाठकों की मदद करता है। –

2

पूर्ण कोड पीडीएफ मुद्रित करने के लिए

UIPrintInteractionController *pc = [UIPrintInteractionController 
             sharedPrintController]; 
    UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
    printInfo.outputType = UIPrintInfoOutputGeneral; 
    printInfo.orientation = UIPrintInfoOrientationPortrait; 
    printInfo.jobName [email protected]"Report"; 

    pc.printInfo = printInfo; 
    pc.showsPageRange = YES; 
    pc.printingItem = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://test.com/Print_for_Client_Name.pdf"]]; 
    // You can use here image or any data type to print. 


UIPrintInteractionCompletionHandler completionHandler = 
^(UIPrintInteractionController *printController, BOOL completed, 
    NSError *error) { 
    if(!completed && error){ 
     NSLog(@"Print failed - domain: %@ error code %ld", error.domain, 
       (long)error.code); 
    } 
}; 


[pc presentFromRect:CGRectMake(0, 0, 300, 300) inView:self.view animated:YES completionHandler:completionHandler]; 
संबंधित मुद्दे