Created
April 17, 2013 09:46
-
-
Save abbood/5403092 to your computer and use it in GitHub Desktop.
PSPDFkit pdf flattening and saving
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pdf delivery | |
-(void)deliverPDFAttachment { | |
NSLog(@"this is attachment path %@", attachmentPath); | |
NSURL *documentURL = [NSURL fileURLWithPath:attachmentPath]; | |
PSPDFDocument *document = [PSPDFDocument PDFDocumentWithURL:documentURL]; | |
document.editableAnnotationTypes = [NSSet setWithObjects: | |
PSPDFAnnotationTypeStringLink, // not added by default. | |
PSPDFAnnotationTypeStringHighlight, | |
PSPDFAnnotationTypeStringUnderline, | |
PSPDFAnnotationTypeStringStrikeout, | |
PSPDFAnnotationTypeStringNote, | |
PSPDFAnnotationTypeStringFreeText, | |
PSPDFAnnotationTypeStringInk, | |
PSPDFAnnotationTypeStringSquare, | |
PSPDFAnnotationTypeStringCircle, | |
nil]; | |
document.delegate = delegate; | |
// Open view controller. Embed into an UINavigationController to enable the toolbar. | |
PSPDFViewController *pdfController = | |
[[PSCExampleAnnotationViewController alloc] initWithDocument:document]; | |
[[delegate navigationController] pushViewController:pdfController animated:YES]; | |
} | |
// PSPDFDocumentDelegate | |
- (void)pdfDocument:(PSPDFDocument *)document didSaveAnnotations:(NSArray *)annotations { | |
NSLog(@"\n\nSaving of %@ successful: %@", document, annotations); | |
NSLog(@"will save flattened annotation to %@",[NSString stringWithFormat:@"%@_annotated",_attachmentPath]); | |
[[PSPDFProcessor defaultProcessor] generatePDFFromDocument:document | |
pageRange:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, document.pageCount)] | |
outputFileURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@_annotated",_attachmentPath]] | |
options:@{kPSPDFProcessorAnnotationTypes : @(PSPDFAnnotationTypeAll)} | |
error:NULL]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment