Reputation: 2260
I want to overwrite a existing PDF file, instead of creating a new one. I don't want to draw the entire PDF file but only one page if there are hundred pages in PDF file.
Actually, I want to place some images on a page of PDF files . It would be wrote over if user tap the save button . Isn't it possible ? Is there any framework or sdk ?
Thank you for any replies.
Upvotes: 2
Views: 1255
Reputation: 2260
Very similar :Merge PDF files on iOS
It's not possible to reopen and continue editing a PDF file . Only read and redraw whole PDF again .
Upvotes: 1
Reputation:
Until now, iOS does not provide a method to edit the entire PDF file . Like this issue,I thought that he also want to modify one of pages.
Third-party lib will be better.
Upvotes: 2
Reputation: 4091
PDF manipulation in iPhone is supported. Apple's documentation is the following http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html
-(void)createPDFFileFromSelectedPageNumber:(int)selectedPageNumber:(NSString*)fileName{
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [arrayPaths objectAtIndex:0];
NSString *outpath = [[NSString alloc]initWithFormat:@"%@/output.pdf",path];
UIGraphicsBeginPDFContextToFile(outpath, CGRectZero, nil);
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
NSURL *url = [[NSURL alloc] initFileURLWithPath:fileName];
CGPDFDocumentRef originalPDF = CGPDFDocumentCreateWithURL((__bridge CFURLRef)url);
CGPDFPageRef pdfPage = CGPDFDocumentGetPage(originalPDF, selectedPageNumber);
CGSize size = CGSizeMake(612.0, 792.0);
CGRect outRect = CGRectMake(0, 0, 612.0, 792.0);
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(pdfPage, kCGPDFMediaBox, outRect, 0, true);
CGContextConcatCTM(context, pdfTransform);
CGContextDrawPDFPage(context, pdfPage);
UIImage *output = UIGraphicsGetImageFromCurrentImageContext();
CGContextSaveGState (context);
UIGraphicsEndImageContext();
[output drawInRect:outRect];
UIGraphicsEndPDFContext();}
Passing the filePath of the source PDF file and pageNumber to the function would give you a new PDF with the single page. Further enhancement can be done by you according to your requirements. Hope at least this helps.
Upvotes: 3