I'm trying to merge multiple PDFs, i'm copying one-by-one all pages into PDF, but the pages have white color text. means text are not in displayable manner. counld you help..?
Thanks In advance...!
My Function to Merge PDF:
-(void)mergePDFs:(NSArray*)pdfList{
CGContextRef pdfContext;
CFStringRef path; CFURLRef url; CFMutableDictionaryRef myDictionary = NULL; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [NSString stringWithFormat:@"%@/abc.pdf", [paths objectAtIndex:0]]; const char *filename = [documentsDirectory UTF8String]; CGRect pageRect = CGRectMake(0, 0, 600, 800); path = CFStringCreateWithCString (NULL, filename, kCFStringEncodingUTF8); url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, 0);
myDictionary = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));
CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name"));
pdfContext = CGPDFContextCreateWithURL (url, &pageRect, myDictionary);
int intLimitedPages=0;
CGPDFDocumentRef document; for(NSString *file in pdfList) { if([file hasSuffix:@".pdf"]) { CGPDFPageRef page;
document = [self readPDF:file]; int count = CGPDFDocumentGetNumberOfPages (document); for(int j = 1; j <= count; j++){ CGContextBeginPage (pdfContext, &pageRect); page = CGPDFDocumentGetPage (document, j); CGContextDrawPDFPage ( pdfContext, page); CGContextEndPage (pdfContext); intLimitedPages+=1; } } } CGPDFDocumentRelease (document);
CGContextFlush(pdfContext); CGContextRelease (pdfContext); CFRelease(url); }
-(CGPDFDocumentRef)readPDF:(NSString*) filename{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; int count = 0;
NSString* filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, filename]; CFURLRef url; CGPDFDocumentRef document;
url = CFURLCreateWithFileSystemPath (NULL, filePath, kCFURLPOSIXPathStyle, 0);
document = CGPDFDocumentCreateWithURL (url);
CFRelease(url);
count = CGPDFDocumentGetNumberOfPages (document);
if (count == 0) {
printf("`%s' needs at least one page!", filePath);
return NULL;
}
return document;
}
Please tell me if there're any mistakes..!