Skip to content

Instantly share code, notes, and snippets.

@abbood
Created April 17, 2013 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abbood/5403092 to your computer and use it in GitHub Desktop.
Save abbood/5403092 to your computer and use it in GitHub Desktop.
PSPDFkit pdf flattening and saving
// 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