2011-12-23 16 views
5

आवेदन मैं बना रहा हूं में, मैं वेब दृश्य में HTML का लंबे समय से पृष्ठ लोड और फिर का उपयोग कर एक पीडीएफ के लिए इसे प्रिंट निम्नलिखित:कोको पीडीएफ पेज बंटवारे

-(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame 
{ 
    if ([frame isEqual:[[self doc] mainFrame]]) 
    { 
     NSMutableData *newData = [[NSMutableData alloc] init]; 
     NSPrintInfo *newInfo = [NSPrintInfo sharedPrintInfo]; 
     NSView *docView = [[[[self doc] mainFrame] frameView] documentView]; 

     NSPrintOperation *newPrintOp = [NSPrintOperation PDFOperationWithView:docView insideRect:docView.bounds toData:newData printInfo:newInfo]; 

     BOOL runPrint = [newPrintOp runOperation]; 
     if (!runPrint) 
     { 
      NSLog(@"Print Failed"); 
     } 
     PDFDocument *newDoc = [[PDFDocument alloc] initWithData:newData]; 
     [newData release]; 
     [self setPdf:newDoc]; 

     //Other code here 
     } 
    } 

समस्या यह है कि जब मैं देखने के लिए है newDoc पर, यह एक पृष्ठ का एक बड़ा पीडीएफ है। मैं जो पसंद करूंगा वह प्रिंटिंग होगा जैसा कि "पीडीएफ के रूप में सहेजें ..." संवाद से होता है - यानी, पीडीएफ को कई उचित आकार के पृष्ठों में विभाजित करना है।

क्या कोई यह जानता है कि इसे कैसे पूरा किया जाए?

NSAutoPagination छवि समान आकार की आयतों में विभाजित है और एक स्तंभ में रख दिया गया है:

मैं के बाद NSPrintInfo *newInfo = [NSPrintInfo sharedPrintInfo];

[newInfo setVerticalPagination:NSAutoPagination]; 
[newInfo setHorizontalPagination:NSAutoPagination]; 

NSAutoPagination निम्नलिखित के रूप में डॉक्स में वर्णन किया गया है निम्नलिखित डालने का प्रयास किया पृष्ठों का मैक ओएस एक्स v10.0 और बाद में उपलब्ध है। NSPrintInfo.h में घोषित किया गया।

इसका मुद्रित पीडीएफ पर कोई प्रभाव नहीं पड़ा।

उत्तर

10

आपको एक बड़े पृष्ठ के साथ एक फ़ाइल मिलती है क्योंकि + PDFOperationWithView: विधि पेजिनेशन का समर्थन नहीं करती है। इसी कारण से - setVerticalPagination: या - setHoriziontalPagination: कुछ भी नहीं बदलता है।

आप "शास्त्रीय" + printOperationWithView:printInfo: विधि का उपयोग करने का प्रयास कर सकते हैं, इसे अस्थायी स्थान पर पीडीएफ को सहेजने के लिए कॉन्फ़िगर करें और फिर प्राप्त फ़ाइल की सामग्री के साथ PDFDocument बनाएं। मुझे आशा है कि नीचे दिए गए कोड का टुकड़ा मदद करेगा।

NSMutableDictionary *dict = [[NSPrintInfo sharedPrintInfo] dictionary]; 
[dict setObject:NSPrintSaveJob forKey:NSPrintJobDisposition]; 
[dict setObject:temporaryFilePath forKey:NSPrintSavePath]; 
NSPrintInfo *pi = [[NSPrintInfo alloc] initWithDictionary:dict]; 
[pi setHorizontalPagination:NSAutoPagination]; 
[pi setVerticalPagination:NSAutoPagination]; 

NSPrintOperation *op = [NSPrintOperation printOperationWithView:[[[webView mainFrame] frameView] documentView] printInfo:pi]; 
[pi release]; 
[op setShowsPrintPanel:NO]; 
[op setShowsProgressPanel:NO]; 

if ([op runOperation]){ 
    PDFDocument *doc = [[[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath: temporaryFilePath]] autorelease]; 
    // do with doc what you want, remove file, etc. 
} 
+0

उत्कृष्ट उत्तर! यदि अगले दिन कोई भी बेहतर जवाब नहीं देता है, तो मैं आपको बक्षीस दूंगा। आपकी सहायता के लिए धन्यवाद. – Daniel

+0

ठीक है, मैं बक्षीस के अंत में जागने वाला नहीं हूं, इसलिए आप जीत गए! – Daniel

+0

इससे मेरी मदद की। अच्छा उत्तर। –

संबंधित मुद्दे