I am converting a pdf file to png image so I can add text to the png then convert back to a pdf. I am using the code below to convert to the png. This is resulting in a substantial decrease in the quality of the appearance. Is there anything that can be done to prevent or minimize the loss of quality?
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writeableDBPath = [documentsDirectory stringByAppendingPathComponent:@"sample.pdf"];
CFStringRef path;
CFURLRef url;
path = CFStringCreateWithCString (NULL, [writeableDBPath UTF8String], kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, 0);
CGPDFDocumentRef myDocument;
myDocument = CGPDFDocumentCreateWithURL(url);
UIGraphicsBeginImageContext(CGSizeMake(612,792));
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(currentContext, 10, 792); //596,842 //640x960,
CGContextScaleCTM(currentContext, 1.0, -1.0); // make sure the page is the right way up
CGPDFPageRef page = CGPDFDocumentGetPage (myDocument, 1); // first page of PDF is page 1 (not zero)
CGContextDrawPDFPage (currentContext, page); // draws the page in the graphics context
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSString* imagePath = [documentsDirectory stringByAppendingPathComponent: @"test.png"];
[UIImagePNGRepresentation(image) writeToFile: imagePath atomically:YES];