CPDFViewController.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // CPDFViewController.m
  3. // PDFViewer
  4. //
  5. // Created by kdan on 2022/11/15.
  6. //
  7. #import <ComPDFKit/ComPDFKit.h>
  8. #import <ComPDFKit/CPDFWatermark.h>
  9. #import <ComPDFKit/CPDFHeaderFooter.h>
  10. #import "CPDFViewController.h"
  11. @interface CPDFViewController () <UIActionSheetDelegate>
  12. @end
  13. @implementation CPDFViewController
  14. - (instancetype)initWithPath:(NSString *)inPath {
  15. if (self = [super init]) {
  16. _path = inPath;
  17. }
  18. return self;
  19. }
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. //add UIBarButtonItem in Navigation
  24. self.navigationController.toolbarHidden = NO;
  25. UIImage *btnMore = [UIImage imageNamed:@"btn_more"];
  26. UIBarButtonItem *ringhtBarItem = [[UIBarButtonItem alloc] initWithImage:btnMore style:UIBarButtonItemStylePlain target:self action:@selector(onClickedOkbtn)];
  27. self.navigationItem.rightBarButtonItem = ringhtBarItem;
  28. //setting URL
  29. NSURL *url = [NSURL fileURLWithPath:_path];
  30. CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
  31. CPDFView *pdfView = [[CPDFView alloc] initWithFrame:self.view.bounds];
  32. pdfView.document = document;
  33. pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  34. [self.view addSubview:pdfView];
  35. }
  36. - (void)onClickedOkbtn {
  37. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  38. UIAlertAction *addWatermarkAction = [UIAlertAction actionWithTitle:@"Add Watermark" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  39. NSLog(@"addWatermarkAction");
  40. }];
  41. UIAlertAction *addHeaderfooterAction = [UIAlertAction actionWithTitle:@"Add Headerfooter" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  42. NSLog(@"addHeaderfooterAction");
  43. }];
  44. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  45. NSLog(@"Cancel Action");
  46. }];
  47. [alertController addAction:addWatermarkAction];
  48. [alertController addAction:addHeaderfooterAction];
  49. [alertController addAction:cancelAction];
  50. [self presentViewController:alertController animated:YES completion:nil];
  51. }
  52. @end