Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Signature support #41

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ILPDFKit.podspec
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Pod::Spec.new do |spec|
spec.source = { :git => "https://github.com/derekblair/ILPDFKit.git", :tag => "1.2.5" }
spec.requires_arc = true
spec.source_files = "ILPDFKit/**/*.{h,m,swift}"
spec.resources = "ILPDFKit/**/*.{xib}"
spec.frameworks = "QuartzCore","UIKit"
spec.public_header_files = "ILPDFKit/**/*.h"
end
Empty file modified ILPDFKit/Controller/ILPDFSerializer.h
100644 → 100755
Empty file.
Empty file modified ILPDFKit/Controller/ILPDFSerializer.m
100644 → 100755
Empty file.
23 changes: 23 additions & 0 deletions ILPDFKit/Controller/ILPDFSignatureController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// ILPDFSignatureController.h
// Pods
//
// Created by Yuriy on 28/08/16.
//
//

#import <UIKit/UIKit.h>
@protocol ILPDFSignatureControllerDelegate;

@interface ILPDFSignatureController : UIViewController

@property (nonatomic, weak) IBOutlet id <ILPDFSignatureControllerDelegate> delegate;
@property (assign) CGSize expectedSignSize;
@end

@protocol ILPDFSignatureControllerDelegate <NSObject>
@optional

- (void) signedWithImage:(UIImage*) signatureImage;

@end
56 changes: 56 additions & 0 deletions ILPDFKit/Controller/ILPDFSignatureController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// ILPDFSignatureController.m
// Pods
//
// Created by Yuriy on 28/08/16.
//
//

#import "ILPDFSignatureController.h"
#import "ILPDFSignatureEditingView.h"

@interface ILPDFSignatureController ()
@property (strong, nonatomic) IBOutlet ILPDFSignatureEditingView *signatureView;

@end

@implementation ILPDFSignatureController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Actions

- (IBAction)clearAction:(UIButton *)sender {

[self.signatureView clearSignature];

}

- (IBAction)signatureAction:(UIButton *)sender {

[self.delegate signedWithImage:[self.signatureView createImageFromSignWithMaxWidth:self.expectedSignSize.width andMaxHeight:self.expectedSignSize.height]];
[self dismissViewControllerAnimated:YES completion:nil];

}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end
74 changes: 74 additions & 0 deletions ILPDFKit/Controller/ILPDFSignatureController.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15400" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15404"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ILPDFSignatureController">
<connections>
<outlet property="signatureView" destination="ifL-qI-elk" id="olh-tz-2y5"/>
<outlet property="view" destination="sMn-ih-wEb" id="Rxh-pY-VWW"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<viewController restorationIdentifier="ILPDFSignatureController" title="ILPDFSignatureController" nibName="ILPDFSignatureController" modalTransitionStyle="crossDissolve" id="5dG-ot-1aR">
<point key="canvasLocation" x="34" y="99"/>
</viewController>
<view contentMode="scaleToFill" id="sMn-ih-wEb">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view alpha="0.40000000000000002" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="0de-6u-pv3">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<color key="backgroundColor" red="0.66666668653488159" green="0.66666668653488159" blue="0.66666668653488159" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ifL-qI-elk" customClass="ILPDFSignatureEditingView">
<rect key="frame" x="12" y="373" width="390" height="150"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" secondItem="ifL-qI-elk" secondAttribute="height" multiplier="231:89" id="b6x-Js-IHH"/>
</constraints>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Kvi-0W-CM7">
<rect key="frame" x="12" y="535" width="195" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="qyX-Ot-A9J"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="15"/>
<state key="normal" title="Clear"/>
<connections>
<action selector="clearAction:" destination="-1" eventType="touchUpInside" id="Jow-OS-0C7"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="h03-4f-Yzb">
<rect key="frame" x="207" y="535" width="195" height="30"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="15"/>
<state key="normal" title="Sign"/>
<connections>
<action selector="signatureAction:" destination="-1" eventType="touchUpInside" id="93m-HN-cy1"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="0de-6u-pv3" secondAttribute="trailing" id="25q-DG-kmJ"/>
<constraint firstItem="ifL-qI-elk" firstAttribute="centerY" secondItem="sMn-ih-wEb" secondAttribute="centerY" id="55W-Hd-zSL"/>
<constraint firstAttribute="bottom" secondItem="0de-6u-pv3" secondAttribute="bottom" id="Dqw-a3-e9b"/>
<constraint firstItem="ifL-qI-elk" firstAttribute="leading" secondItem="sMn-ih-wEb" secondAttribute="leading" constant="12" id="IhV-IQ-XGP"/>
<constraint firstItem="Kvi-0W-CM7" firstAttribute="leading" secondItem="ifL-qI-elk" secondAttribute="leading" id="NMJ-iq-TfC"/>
<constraint firstItem="h03-4f-Yzb" firstAttribute="width" secondItem="Kvi-0W-CM7" secondAttribute="width" id="Qx5-pg-lzc"/>
<constraint firstItem="h03-4f-Yzb" firstAttribute="leading" secondItem="Kvi-0W-CM7" secondAttribute="trailing" id="SOv-Gn-1qJ"/>
<constraint firstItem="0de-6u-pv3" firstAttribute="leading" secondItem="sMn-ih-wEb" secondAttribute="leading" id="Yi3-5c-DeP"/>
<constraint firstItem="h03-4f-Yzb" firstAttribute="trailing" secondItem="ifL-qI-elk" secondAttribute="trailing" id="Zjd-61-z0p"/>
<constraint firstItem="0de-6u-pv3" firstAttribute="top" secondItem="sMn-ih-wEb" secondAttribute="top" id="fOp-sc-LHd"/>
<constraint firstItem="h03-4f-Yzb" firstAttribute="centerY" secondItem="Kvi-0W-CM7" secondAttribute="centerY" id="gji-ZF-hyx"/>
<constraint firstItem="Kvi-0W-CM7" firstAttribute="top" secondItem="ifL-qI-elk" secondAttribute="bottom" constant="12" id="kWy-gM-9fz"/>
<constraint firstItem="ifL-qI-elk" firstAttribute="centerX" secondItem="sMn-ih-wEb" secondAttribute="centerX" id="pHf-FB-bua"/>
</constraints>
<point key="canvasLocation" x="-274" y="-546"/>
</view>
</objects>
</document>
2 changes: 1 addition & 1 deletion ILPDFKit/Controller/ILPDFViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

@class ILPDFView;
@class ILPDFDocument;

@class ILPDFSignatureControllerDelegate;

NS_ASSUME_NONNULL_BEGIN

Expand Down
74 changes: 68 additions & 6 deletions ILPDFKit/Controller/ILPDFViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,63 @@


#import "ILPDFFormContainer.h"
#import "ILPDFSignatureController.h"
#import "ILPDFFormSignatureField.h"
#import "ILPDFViewController.h"
#import "ILPDFDocument.h"
#import "ILPDFView.h"

@interface ILPDFViewController(Private)
@interface ILPDFViewController(Private) <ILPDFSignatureControllerDelegate>
- (void)loadPDFView;
@property (nonatomic, strong) ILPDFView *pdfView;
@end


@implementation ILPDFViewController
@implementation ILPDFViewController {
ILPDFView *_pdfView;
ILPDFSignatureController *signatureController;
ILPDFFormSignatureField *signatureField;
}

#pragma mark - UIViewController

- (void) viewDidLoad {

[super viewDidLoad];
self.edgesForExtendedLayout = UIRectEdgeNone;
self.view.backgroundColor = [UIColor whiteColor];
}

- (void) viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(showSignatureViewController:)
name:@"SignatureNotification"
object:nil];


}

- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// Alter or remove to define your own layout logic for the ILPDFView.
_pdfView.frame = CGRectMake(0,self.topLayoutGuide.length,self.view.bounds.size.width,self.view.bounds.size.height-self.topLayoutGuide.length - self.bottomLayoutGuide.length);
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
[self loadPDFView];
}
}

- (void)viewDidLoad {
[super viewDidLoad];
self.edgesForExtendedLayout = UIRectEdgeNone;
self.view.backgroundColor = [UIColor whiteColor];
- (void) viewWillDisappear:(BOOL)animated
{

[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];

}

#pragma mark - ILPDFViewController
Expand Down Expand Up @@ -84,6 +117,35 @@ - (void)loadPDFView {
[self applyConstraintsToPDFView];
}

#pragma mark - KVO

- (void) showSignatureViewController:(NSNotification *) notification {

if ([notification.object isKindOfClass:[ILPDFFormSignatureField class]]) {
signatureField = notification.object;
}
NSBundle *bundle = [NSBundle bundleForClass:ILPDFSignatureController.classForCoder];

signatureController = [[ILPDFSignatureController alloc] initWithNibName:@"ILPDFSignatureController" bundle:bundle];
signatureController.expectedSignSize = signatureField.frame.size;
signatureController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
signatureController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
signatureController.delegate = self;
[self presentViewController:signatureController animated:YES completion:nil];

}

#pragma mark - Signature Controller Delegate

- (void) signedWithImage:(UIImage*) signatureImage {

[signatureField removeButtonTitle];
signatureField.signatureImage.image = signatureImage;
[signatureField informDelegateAboutNewImage];
signatureField = nil;

}



@end
58 changes: 58 additions & 0 deletions ILPDFKit/ILPDFKit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// ILPDFKit.h
// ILPDFKit
//
// Created by Derek Blair on 2016-03-19.
// Copyright © 2016 Derek Blair. All rights reserved.
//

#import <UIKit/UIKit.h>

//! Project version number for ILPDFKit.
FOUNDATION_EXPORT double ILPDFKitVersionNumber;

//! Project version string for ILPDFKit.
FOUNDATION_EXPORT const unsigned char ILPDFKitVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <ILPDFKit/PublicHeader.h>


#import <ILPDFKit/ILPDFDictionary.h>
#import <ILPDFKit/ILPDFArray.h>
#import <ILPDFKit/ILPDFStream.h>
#import <ILPDFKit/ILPDFString.h>
#import <ILPDFKit/ILPDFName.h>
#import <ILPDFKit/ILPDFNumber.h>
#import <ILPDFKit/ILPDFNull.h>

#import <ILPDFKit/ILPDFForm.h>
#import <ILPDFKit/ILPDFPage.h>
#import <ILPDFKit/ILPDFDocument.h>
#import <ILPDFKit/ILPDFView.h>
#import <ILPDFKit/ILPDFWidgetAnnotationView.h>
#import <ILPDFKit/ILPDFViewController.h>
#import <ILPDFKit/ILPDFUtility.h>


#import <QuartzCore/QuartzCore.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

// This is the color for all pdf forms.
#define ILPDFWidgetColor [UIColor colorWithRed:0.7 green:0.85 blue:1.0 alpha:0.7]

// PDF uses ASCII for readable characters, but allows any 8 bit value unlike ASCII, so we use an extended ASCII set here.
// The character mapped to encoded bytes over 127 have no significance, and are octal escaped if needed to be read as text in the PDF file itself.
#define ILPDFStringCharacterEncoding NSISOLatin1StringEncoding

// Character macros
#define isWS(c) ((c) == 0 || (c) == 9 || (c) == 10 || (c) == 12 || (c) == 13 || (c) == 32)
#define isDelim(c) ((c) == '(' || (c) == ')' || (c) == '<' || (c) == '>' || (c) == '[' || (c) == ']' || (c) == '{' || (c) == '}' || (c) == '/' || (c) == '%')
#define isODelim(c) ((c) == '(' || (c) == '<' || (c) == '[')
#define isCDelim(c) ((c) == ')' || (c) == '>' || (c) == ']')

#define ILPDFFormMinFontSize 8
#define ILPDFFormMaxFontSize 22



3 changes: 3 additions & 0 deletions ILPDFKit/Model/ILPDFDocument.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (NSString *)formXML;

// @return A string containing an json representation of the forms of the document and their values. Used for submitting the form.
- (NSString *)formJSON;

@end

NS_ASSUME_NONNULL_END
11 changes: 11 additions & 0 deletions ILPDFKit/Model/ILPDFDocument.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ - (NSString *)formXML {
return [self.forms formXML];
}

- (NSString *)formJSON {
NSArray <ILPDFForm*>*forms = [self.forms allForms];
NSMutableDictionary *formValues = [NSMutableDictionary new];
for (ILPDFForm *form in forms) {
formValues[form.name] = form.value ? form.value : @"";
}
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:formValues options:NSJSONWritingPrettyPrinted error:&err];
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

- (NSData *)savedStaticPDFData {
NSUInteger numberOfPages = [self numberOfPages];
NSMutableData *pageData = [NSMutableData data];
Expand Down
Empty file modified ILPDFKit/Model/ILPDFForm.h
100644 → 100755
Empty file.
Loading