2010-03-15 17 views
8

आईएएम पीडीएफ फाइल में यूआईएममेज को सहेजने की कोशिश कर रहा है। मैं यह कैसे कर सकता हूं? मैं पीडीएफ फ़ाइल में कैसे सहेजूं और छवि को सहेजूं और फिर उस पीडीएफ फाइल को निर्यात करूं? कृपया मुझे जिस मुद्दे का सामना करना पड़ा उसका समाधान सुझाएं।यूआईएममेज को पीडीएफ फाइल में कनवर्ट करना

धन्यवाद।

+0

क्यों? हालांकि यह संभव है, पीडीएफ दस्तावेजों और वेक्टर ग्राफिक्स को संग्रहीत करने के लिए अनुकूलित किया गया है, और UIImage एक बिटमैप है ... – kennytm

उत्तर

3

मेरी समझ यह है कि आप CGPDFContext बनाएंगे, इसमें अपना यूआईएममेज बनाएं, और इसे फ़ाइल में सहेजें। हालांकि, मैंने खुद ऐसा नहीं किया है।

15

हैलो वहाँ मुझे पता चला है कि यह काम करता है, उम्मीद है कि यह मदद करता है!

-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename 
    { 
     // Creates a mutable data object for updating with binary data, like a byte array 
     NSMutableData *pdfData = [NSMutableData data]; 

     // Points the pdf converter to the mutable data object and to the UIView to be converted 
     UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil); 
     UIGraphicsBeginPDFPage(); 

     // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData 
     [aView.layer renderInContext:UIGraphicsGetCurrentContext()]; 

     // remove PDF rendering context 
     UIGraphicsEndPDFContext(); 

     // Retrieves the document directories from the iOS device 
     NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES); 

     NSString* documentDirectory = [documentDirectories objectAtIndex:0]; 
     NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename]; 

     // instructs the mutable data object to write its context to a file on disk 
     [pdfData writeToFile:documentDirectoryFilename atomically:YES]; 
     NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename); 
    } 
+0

एक अच्छी अवधारणा की तरह लगता है, लेकिन एक खाली पीडीएफ फ़ाइल खींचता है? "AView" drawRect पर क्या आवश्यक है? – WrightsCS

+1

पूरी तरह से यह काम कर रहा है .... क्यू sooooooooo बहुत streeter amduser440071 –

0

मुझे एक खाली पीडीएफ भी मिला। हालांकि यह अब काम कर रहा है। बदलने का प्रयास करें:

//[aView drawRect:aView.bounds]; // <- This 

[aView.layer renderInContext:UIGraphicsGetCurrentContext()]; // <- To This 
-1

आप एक PDF ग्राफिक्स संदर्भ शुरू कर सकते हैं, और फिर इसे में एक छवि आकर्षित, का उपयोग करते हुए:

[UIImage drawInRect: someRect]; 

आप या तो दस्तावेज़ देख सकेंगे, वे एक पैदा करने का एक अच्छा स्पष्टीकरण दे सकते हैं पीडीएफ। पीडीएफ पीढ़ी here पर एक अच्छा ट्यूटोरियल है।

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