// // CPDFViewController.m // PDFViewer // // Created by kdan on 2022/11/15. // #import #import #import #import "CPDFViewController.h" @interface CPDFViewController () @end @implementation CPDFViewController - (instancetype)initWithPath:(NSString *)inPath { if (self = [super init]) { _path = inPath; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //add UIBarButtonItem in Navigation self.navigationController.toolbarHidden = NO; UIImage *btnMore = [UIImage imageNamed:@"btn_more"]; UIBarButtonItem *ringhtBarItem = [[UIBarButtonItem alloc] initWithImage:btnMore style:UIBarButtonItemStylePlain target:self action:@selector(onClickedOkbtn)]; self.navigationItem.rightBarButtonItem = ringhtBarItem; //setting URL NSURL *url = [NSURL fileURLWithPath:_path]; CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url]; CPDFView *pdfView = [[CPDFView alloc] initWithFrame:self.view.bounds]; pdfView.document = document; pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [self.view addSubview:pdfView]; } - (void)onClickedOkbtn { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *addWatermarkAction = [UIAlertAction actionWithTitle:@"Add Watermark" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"addWatermarkAction"); }]; UIAlertAction *addHeaderfooterAction = [UIAlertAction actionWithTitle:@"Add Headerfooter" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"addHeaderfooterAction"); }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { NSLog(@"Cancel Action"); }]; [alertController addAction:addWatermarkAction]; [alertController addAction:addHeaderfooterAction]; [alertController addAction:cancelAction]; [self presentViewController:alertController animated:YES completion:nil]; } @end