Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/issue-649'
Browse files Browse the repository at this point in the history
  • Loading branch information
steipete committed Feb 28, 2014
2 parents 029e46d + 8636be0 commit 3849763
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
11 changes: 6 additions & 5 deletions Examples/PSPDFCatalog/Annotations/PSCSignAllPagesExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,17 @@ - (UIViewController *)invokeWithDelegate:(id<PSCExampleRunnerDelegate>)delegate
NSURL *tempURL = PSCTempFileURLWithPathExtension(@"flattened_signaturetest", @"pdf");
// Perform in background to allow progress showing.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
PSPDFStatusHUDItem *status = [PSPDFStatusHUDItem progressWithText:PSPDFLocalizeWithEllipsis(@"Preparing")];
[status push];

[PSPDFProcessor.defaultProcessor generatePDFFromDocument:document pageRanges:@[[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, document.pageCount)]] outputFileURL:tempURL options:@{PSPDFProcessorAnnotationTypes : @(PSPDFAnnotationTypeAll)} progressBlock:^(NSUInteger currentPage, NSUInteger numberOfProcessedPages, NSUInteger totalPages) {
// Access UI only from main thread.
dispatch_async(dispatch_get_main_queue(), ^{
[PSPDFProgressHUD showProgress:(numberOfProcessedPages+1)/(float)totalPages status:PSPDFLocalizeWithEllipsis(@"Preparing")];
});
status.progress = (numberOfProcessedPages+1)/(float)totalPages;
} error:NULL];

[status pop];

// completion
dispatch_async(dispatch_get_main_queue(), ^{
[PSPDFProgressHUD dismiss];
PSPDFDocument *flattenedDocument = [PSPDFDocument documentWithURL:tempURL];
PSPDFViewController *pdfController = [[PSPDFViewController alloc] initWithDocument:flattenedDocument];
[delegate.currentViewController.navigationController pushViewController:pdfController animated:YES];
Expand Down
16 changes: 12 additions & 4 deletions Examples/PSPDFCatalog/Customization/PSCTextExtractionExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#import "PSCTabbedExampleViewController.h"
#import "PSCFileHelper.h"
#import "UINavigationController+PSCKeyboardDismissal.h"
#import <objc/runtime.h>
#import "PSCExample.h"
#import "PSPDFStatusHUD.h"

#import <objc/runtime.h>

@interface PSCFullTextSearchExample : PSCExample @end
@interface PSCConvertMarkupStringToPDFExample : PSCExample @end
Expand Down Expand Up @@ -145,14 +147,20 @@ - (UIViewController *)invokeWithDelegate:(id<PSCExampleRunnerDelegate>)delegate
//URL = [NSURL fileURLWithPath:PSPDFResolvePathNames(@"/Bundle/Samples/test2.key", nil)];

// start the conversion
[PSPDFProgressHUD showWithStatus:@"Converting..." maskType:PSPDFProgressHUDMaskTypeGradient];
PSPDFStatusHUDItem *status = [PSPDFStatusHUDItem new];
[status setText:@"Converting..."];
[status setHUDStyle:PSPDFStatusHUDStyleGradient];

[PSPDFProcessor.defaultProcessor generatePDFFromURL:URL outputFileURL:outputURL options:nil completionBlock:^(NSURL *fileURL, NSError *error) {
if (error) {
[PSPDFProgressHUD dismiss];
[status pop];
[[[UIAlertView alloc] initWithTitle:@"Conversion failed" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
}else {
// generate document and show it
[PSPDFProgressHUD showSuccessWithStatus:@"Finished"];
PSPDFStatusHUDItem *statusDone = [PSPDFStatusHUDItem successWithText:@"Done"];
[statusDone pushAndPopWithDelay:2.0f];
[status pop];

PSPDFDocument *document = [PSPDFDocument documentWithURL:fileURL];
PSPDFViewController *pdfController = [[PSPDFViewController alloc] initWithDocument:document];

Expand Down
22 changes: 17 additions & 5 deletions Examples/PSPDFCatalog/PSCatalogViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
#import "PSCAvailability.h"
#import "UIColor+PSPDFCatalog.h"
#import "PSCPopoverTestViewController.h"
#import "PSPDFStatusHUD.h"

#import <objc/runtime.h>

// Crypto support
Expand Down Expand Up @@ -306,12 +308,15 @@ - (void)createTableContent {
NSURL *tempURL = PSCTempFileURLWithPathExtension(@"protected", @"pdf");
PSPDFDocument *hackerMagDoc = [PSPDFDocument documentWithURL:hackerMagURL];

PSPDFStatusHUDItem *status = [PSPDFStatusHUDItem progressWithText:PSPDFLocalizeWithEllipsis(@"Preparing")];
[status push];

// With password protected pages, PSPDFProcessor can only add link annotations.
[PSPDFProcessor.defaultProcessor generatePDFFromDocument:hackerMagDoc pageRanges:@[[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, hackerMagDoc.pageCount)]] outputFileURL:tempURL options:@{(id)kCGPDFContextUserPassword : password, (id)kCGPDFContextOwnerPassword : password, (id)kCGPDFContextEncryptionKeyLength : @128, PSPDFProcessorAnnotationAsDictionary : @YES, PSPDFProcessorAnnotationTypes : @(PSPDFAnnotationTypeLink)} progressBlock:^(NSUInteger currentPage, NSUInteger numberOfProcessedPages, NSUInteger totalPages) {
[PSPDFProgressHUD showProgress:numberOfProcessedPages/(float)totalPages status:PSPDFLocalizeWithEllipsis(@"Preparing")];
status.progress = numberOfProcessedPages/(float)totalPages;
} error:NULL];

[PSPDFProgressHUD dismiss];
[status pop];

// show file
PSPDFDocument *document = [PSPDFDocument documentWithURL:tempURL];
Expand Down Expand Up @@ -1440,14 +1445,21 @@ - (void)createTableContent {
[testSection addContent:[PSContent contentWithTitle:@"PSPDFProcessor PPTX (Microsoft Office) conversion" block:^UIViewController *{
NSURL *URL = [NSURL fileURLWithPath:@"/Users/steipete/Documents/Projects/PSPDFKit_meta/converts/Neu_03_VZ3_Introduction.pptx"];
NSURL *outputURL = PSCTempFileURLWithPathExtension(@"converted", @"pdf");
[PSPDFProgressHUD showWithStatus:@"Converting..." maskType:PSPDFProgressHUDMaskTypeGradient];

PSPDFStatusHUDItem *status = [PSPDFStatusHUDItem indeterminateProgressWithText:@"Converting..."];
[status setHUDStyle:PSPDFStatusHUDStyleGradient];
[status push];

[PSPDFProcessor.defaultProcessor generatePDFFromURL:URL outputFileURL:outputURL options:nil completionBlock:^(NSURL *fileURL, NSError *error) {
if (error) {
[PSPDFProgressHUD dismiss];
[status pop];
[[[UIAlertView alloc] initWithTitle:@"Conversion failed" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
}else {
PSPDFStatusHUDItem *statusDone = [PSPDFStatusHUDItem successWithText:@"Done"];
[statusDone setHUDStyle:PSPDFStatusHUDStyleGradient];
[statusDone pushAndPopWithDelay:2.0f];

// generate document and show it
[PSPDFProgressHUD showSuccessWithStatus:@"Finished"];
PSPDFDocument *document = [PSPDFDocument documentWithURL:fileURL];
PSPDFViewController *pdfController = [[PSPDFViewController alloc] initWithDocument:document];
[self.navigationController pushViewController:pdfController animated:YES];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,19 @@ - (void)createTemporaryPDFAndOpenEmailControllerWithAnnotationsFlattened:(BOOL)f
// Crunch the PDF
if (selectedPages.count) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
PSPDFStatusHUDItem *status = [PSPDFStatusHUDItem progressWithText:PSPDFLocalizeWithEllipsis(@"Preparing")];
[status push];

NSDictionary *options = flattened ? @{PSPDFProcessorAnnotationTypes : @(PSPDFAnnotationTypeAll&~PSPDFAnnotationTypeLink)} : @{PSPDFProcessorAnnotationAsDictionary : @YES};
// TODO: use file-based version to support larger PDFs.
NSError *error = nil;
NSData *data = [PSPDFProcessor.defaultProcessor generatePDFFromDocument:self.document pageRanges:@[selectedPages] options:options progressBlock:^(NSUInteger currentPage, NSUInteger numberOfProcessedPages, NSUInteger totalPages) {
[PSPDFProgressHUD showProgress:(numberOfProcessedPages + 1) / (float)totalPages status:PSPDFLocalizeWithEllipsis(@"Preparing")];
status.progress = (numberOfProcessedPages + 1) / (float)totalPages;
} error:&error];

//
[status pop];

dispatch_async(dispatch_get_main_queue(), ^{
[PSPDFProgressHUD dismiss];
if (data) {
[mailViewController addAttachmentData:data mimeType:@"application/pdf" fileName:@"SelectedPages.pdf"];
[((PSPDFViewController *)self.parentViewController) presentModalOrInPopover:mailViewController embeddedInNavigationController:NO withCloseButton:NO animated:YES sender:nil options:@{PSPDFPresentOptionAlwaysModal : @YES}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#import "PSCTwoFingerSwipeGestureViewController.h"

#import "PSPDFStatusHUD.h"

@interface PSCSwipePagingScrollView : PSPDFPagingScrollView
@property (nonatomic, strong) UIPanGestureRecognizer *customPanRecognizer;
@property (nonatomic, strong) UISwipeGestureRecognizer *leftSwipeRecognizer;
Expand Down Expand Up @@ -79,10 +81,10 @@ - (id)initWithFrame:(CGRect)frame {

- (void)handleGestureFrom:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
[PSPDFProgressHUD showSuccessWithStatus:@"Swiped left"];
[[PSPDFStatusHUDItem successWithText:@"Swiped Left"] pushAndPopWithDelay:2.0f];
NSLog(@"Swiped left.");
} else {
[PSPDFProgressHUD showSuccessWithStatus:@"Swiped right"];
[[PSPDFStatusHUDItem successWithText:@"Swiped Right"] pushAndPopWithDelay:2.0f];
NSLog(@"Swiped right.");
}
}
Expand Down

0 comments on commit 3849763

Please sign in to comment.