Hi Devs,
I am trying to generate a PDF which copies content from another PDF. To do so i have implemented following code which works fine for most of PDF but it doesn't work for attached PDF file.
CGContextRef pdfContext;
CFStringRef path;
CFURLRef url;
CFMutableDictionaryRef myDictionary = NULL;
NSInteger pageWidth,pageHeight;
CGPDFPageRef page;
filename = [pdfFilePath UTF8String];
path = CFStringCreateWithCString (NULL, filename,kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath (NULL, path,kCFURLPOSIXPathStyle,0);
CFRelease (path);
myDictionary = CFDictionaryCreateMutable(NULL, 0,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionar yValueCallBacks);
struct CGRect pageRect = CGRectMake(0, 0, 768, 960);
CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("PDFReaderDemo"));
CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("Hello"));
pdfContext = CGPDFContextCreateWithURL(url, &pageRect, myDictionary);
CGContextBeginPage (pdfContext, &pageRect);
CGContextSaveGState(pdfContext);
float fltScaleX = 768.0f/pageWidth;
float fltScaleY = 960.0f/pageHeight;
CGRect drawRect = CGRectMake(0.0f, 0.0f, 768, 960);
CGContextTranslateCTM(pdfContext, 0.0f, 960.0f);
CGContextScaleCTM(pdfContext,fltScaleX, fltScaleY);
struct CGRect mediaBox123 = CGRectMake(0, 0, 768.0, -960.0);
/////////////// Code implemented to copy PDF page from another PDF
page = CGPDFDocumentGetPage (document, i+1);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, mediaBox123, 0, true);
CGContextConcatCTM(pdfContext, pdfTransform);
CGContextClipToRect(pdfContext, drawRect);
CGContextDrawPDFPage(pdfContext, page);
CGContextRestoreGState(pdfContext);
CGContextEndPage(pdfContext);
CGPDFContextClose(pdfContext);
PDF Link:
Download Sample1.PDF for free on uploading.com
Thanks in Advance...