123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- //
- // CPDFViewController.m
- // PDFViewer
- //
- // Created by kdan on 2022/11/15.
- //
- #import <ComPDFKit/ComPDFKit.h>
- #import <ComPDFKit/CPDFHeaderFooter.h>
- #import "CPDFViewController.h"
- #import "CPDFHeaderFooterAddController.h"
- #import "CPDFHeaderFooterDeleteController.h"
- #import "CPDFBatesSettingController.h"
- #import "CPDFHeaderFooterSettingController.h"
- @interface CPDFViewController () <UIActionSheetDelegate>
- @property (nonatomic,strong) CPDFKitPlatformImage *image;
- @property (nonatomic,assign) CGSize size;
- @property (nonatomic,strong) CPDFHeaderFooter *headerFooter;
- @property (nonatomic,strong) CPDFDocument *document;
- @property (nonatomic,strong) CPDFView *pdfView;
- @property (nonatomic,strong) CPDFHeaderFooterSettingController *headefooterControl;
- @property (nonatomic,strong) CPDFModelData *modelData;
- @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 = YES;
- 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];
- _document = [[CPDFDocument alloc] initWithURL:url];
- //get document frist image
- CPDFPage *page = [_document pageAtIndex:0];
- _size = [_document pageSizeAtIndex:0];
- _image = [page thumbnailOfSize:_size];
- //get document view
- _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];
- //add watermark action
- UIAlertAction *addWatermarkAction = [UIAlertAction actionWithTitle:@"Add Watermark" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"addWatermarkAction");
- }];
- //setting headerfooter action
- UIAlertAction *settingHeaderFooter = [UIAlertAction actionWithTitle:@"Setting Headerfooter" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- self.headefooterControl = [[CPDFHeaderFooterSettingController alloc] initWithIamge:self.image WithSize:self.size WithDocument:self.document WithView:self.pdfView];
- [self addChildViewController:self.headefooterControl];
- [self.view addSubview:self.headefooterControl.view];
- [self.navigationController pushViewController:self.headefooterControl animated:NO];
- }];
- //seeting bates action
- UIAlertAction *settingBatesAction = [UIAlertAction actionWithTitle:@"Setting Bates" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- CPDFBatesSettingController *batesBatesControl = [[CPDFBatesSettingController alloc] initWithIamge:self.image WithSize:self.size];
- [self addChildViewController:batesBatesControl];
- [self.view addSubview:batesBatesControl.view];
- [self.navigationController pushViewController:batesBatesControl animated:NO];
- }];
- //cancel action
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"Cancel Action");
- }];
- [alertController addAction:addWatermarkAction];
- [alertController addAction:settingHeaderFooter];
- [alertController addAction:settingBatesAction];
- [alertController addAction:cancelAction];
- [self presentViewController:alertController animated:YES completion:nil];
- self.pdfView = self.headefooterControl.pdfView;
- [self.view addSubview:self.pdfView];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getModel:) name:@"getSettingModel" object:nil];
- }
- - (void)getModel:(NSNotification *)text {
- self.modelData = self.headefooterControl.modelData;
- self.headerFooter = [self.document headerFooter];
- self.headerFooter.pageString = @"1";
- [self.headerFooter setText:@"1" atIndex:self.modelData.fontPosition];
- [self.headerFooter setFontSize:self.modelData.fontSize atIndex:self.modelData.fontPosition];
- [self.headerFooter setTextColor:self.modelData.fontColor atIndex:self.modelData.fontPosition];
- [self.headerFooter update];
- NSURL *url = [NSURL fileURLWithPath:self.path];
- [self.document writeToURL:url];
- _document = [[CPDFDocument alloc] initWithURL:url];
- _pdfView = [[CPDFView alloc] initWithFrame:self.view.bounds];
- _pdfView.document = _document;
- _pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- [self.view addSubview:_pdfView];
- }
- @end
|