मैंने UIView से पीडीएफ उत्पन्न करने के लिए निम्न विधियों का उपयोग किया है। वे सब के सब PDF बनाने लेकिन गुणवत्ता खो देता है:आईओएस - प्रतिपादन द्वारा UIView से पीडीएफ जेनरेट करना गुणवत्ता खो देता है
विधि 1:
@implementation UIView(PDFWritingAdditions)
- (void)renderInPDFFile:(NSString*)path
{
CGRect mediaBox = self.bounds;
CGContextRef ctx = CGPDFContextCreateWithURL((__bridge_retained CFURLRef)[NSURL fileURLWithPath:path], &mediaBox, NULL);
CGPDFPageRef page;
CGContextDrawPDFPage(ctx, page);
CGPDFContextBeginPage(ctx, NULL);
// Also tried following commented lines but no luck
// CGContextSetFlatness(ctx, 0.1);
// CGContextSetAllowsAntialiasing(ctx, YES);
// CGContextSetAllowsFontSmoothing(ctx, YES);
// CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -mediaBox.size.height);
[self.layer renderInContext:ctx];
CGPDFContextEndPage(ctx);
CFRelease(ctx);
}
@end
विधि 2:
- (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();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[aView.layer renderInContext:pdfContext];
// 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);
}
मुझे लगता है कि मुझे यकीन है नहीं पीडीएफ संदर्भ के लिए कुछ सेटिंग्स गायब हो सकता है। इसके अलावा, मैं विधि है जो ठीक उसी गुणवत्ता है निम्नलिखित के साथ UIView से png छवि बनाने है:
- (UIImage *)imageFromView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Retrieves the document directories from the iOS device
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:@"pdf.png"];
// instructs the mutable data object to write its context to a file on disk
[UIImagePNGRepresentation(img) writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
return img;
}
कोई देख सकता हूँ मैं गलत क्या कर रहा हूँ? धन्यवाद।
यह गुणवत्ता कैसे खो देता है? –
यहां मूल दृश्य लिंक है: और पीडीएफ लिंक के बाद: –
iEamin
[उच्च गुणवत्ता का संभावित डुप्लिकेट पीडीएफ से यूआईएममेज] (http://stackoverflow.com/questions/14152477/high-quality-uiimage-from-pdf) – nielsbot