forked from mkernahan/BNHtmlPdfKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BNHtmlPdfKit.h
372 lines (296 loc) · 11.4 KB
/
BNHtmlPdfKit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
//
// BNHtmlPdfKit.h
//
// Created by Brent Nycum.
// Copyright (c) 2013 Brent Nycum. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol BNHtmlPdfKitDelegate;
// http://en.wikipedia.org/wiki/Paper_size
typedef enum {
BNPageSizeLetter,
BNPageSizeGovernmentLetter,
BNPageSizeLegal,
BNPageSizeJuniorLegal,
BNPageSizeLedger,
BNPageSizeTabloid,
BNPageSizeA0,
BNPageSizeA1,
BNPageSizeA2,
BNPageSizeA3,
BNPageSizeA4,
BNPageSizeA5,
BNPageSizeA6,
BNPageSizeA7,
BNPageSizeA8,
BNPageSizeA9,
BNPageSizeA10,
BNPageSizeB0,
BNPageSizeB1,
BNPageSizeB2,
BNPageSizeB3,
BNPageSizeB4,
BNPageSizeB5,
BNPageSizeB6,
BNPageSizeB7,
BNPageSizeB8,
BNPageSizeB9,
BNPageSizeB10,
BNPageSizeC0,
BNPageSizeC1,
BNPageSizeC2,
BNPageSizeC3,
BNPageSizeC4,
BNPageSizeC5,
BNPageSizeC6,
BNPageSizeC7,
BNPageSizeC8,
BNPageSizeC9,
BNPageSizeC10,
BNPageSizeJapaneseB0,
BNPageSizeJapaneseB1,
BNPageSizeJapaneseB2,
BNPageSizeJapaneseB3,
BNPageSizeJapaneseB4,
BNPageSizeJapaneseB5,
BNPageSizeJapaneseB6,
BNPageSizeJapaneseB7,
BNPageSizeJapaneseB8,
BNPageSizeJapaneseB9,
BNPageSizeJapaneseB10,
BNPageSizeJapaneseB11,
BNPageSizeJapaneseB12,
BNPageSizeCustom
} BNPageSize;
@interface BNHtmlPdfKit : NSObject
/**
The paper size of the generated PDF.
*/
@property (nonatomic, assign) BNPageSize pageSize;
/**
Custom page size.
*/
@property (nonatomic, assign) CGSize customPageSize;
/**
Is page landscape?
*/
@property (nonatomic, assign, getter=isLandscape) BOOL landscape;
/**
Top and Bottom page margins.
*/
@property (nonatomic, assign) CGFloat topAndBottomMarginSize;
/**
Left and Right page margins.
*/
@property (nonatomic, assign) CGFloat leftAndRightMarginSize;
/**
Base URL to use.
*/
@property (nonatomic, retain) NSURL *baseUrl;
/**
The receiver's `delegate`.
The `delegate` is sent messages when content is loading.
*/
@property (nonatomic, assign) id<BNHtmlPdfKitDelegate> delegate;
/**
Creates a BNHtmlPdfKit object to save a URL as PDF.
@param url URL to save PDF of.
@param completion Block to be notified when PDF data is generated.
@param failure Block to be notified of failure.
*/
+ (BNHtmlPdfKit *)saveUrlAsPdf:(NSURL *)url success:(void (^)(NSData *pdfData))completion failure:(void (^)(NSError *error))failure;
/**
Creates a BNHtmlPdfKit object to save a URL as PDF with BNPageSize.
@param url URL to save PDF of.
@param pageSize BNPageSize of the page to be generated.
@param completion Block to be notified when PDF data is generated.
@param failure Block to be notified of failure.
*/
+ (BNHtmlPdfKit *)saveUrlAsPdf:(NSURL *)url pageSize:(BNPageSize)pageSize success:(void (^)(NSData *pdfData))completion failure:(void (^)(NSError *error))failure;
/**
Creates a BNHtmlPdfKit object to save a URL as PDF with BNPageSize and if in landscape.
@param url URL to save PDF of.
@param pageSize BNPageSize of the page to be generated.
@param landscape Should the page be landscape.
@param completion Block to be notified when PDF data is generated.
@param failure Block to be notified of failure.
*/
+ (BNHtmlPdfKit *)saveUrlAsPdf:(NSURL *)url pageSize:(BNPageSize)pageSize isLandscape:(BOOL)landscape success:(void (^)(NSData *pdfData))completion failure:(void (^)(NSError *error))failure;
/**
Creates a BNHtmlPdfKit object to save a URL as PDF with BNPageSize, landscape orientation, and margin sizes.
@param url URL to save PDF of.
@param pageSize BNPageSize of the page to be generated.
@param landscape Should the page be landscape.
@param topAndBottom Top and bottom margin size.
@param leftAndRight Left and right margin size.
@param completion Block to be notified when PDF data is generated.
@param failure Block to be notified of failure.
*/
+ (BNHtmlPdfKit *)saveUrlAsPdf:(NSURL *)url pageSize:(BNPageSize)pageSize isLandscape:(BOOL)landscape topAndBottomMarginSize:(CGFloat)topAndBottom leftAndRightMarginSize:(CGFloat)leftAndRight success:(void (^)(NSData *pdfData))completion failure:(void (^)(NSError *error))failure;
/**
Creates a BNHtmlPdfKit object to save a URL as a PDF file.
@param url URL to save PDF of.
@param completion Block to be notified when PDF file is generated.
@param failure Block to be notified of failure.
*/
+ (BNHtmlPdfKit *)saveUrlAsPdf:(NSURL *)url toFile:(NSString *)filename success:(void (^)(NSString *filename))completion failure:(void (^)(NSError *error))failure;
/**
Creates a BNHtmlPdfKit object to save a URL as a PDF file with BNPageSize.
@param url URL to save PDF of.
@param filename Filename to save file as.
@param pageSize BNPageSize of the page to be generated.
@param leftAndRight Left and right margin size.
@param completion Block to be notified when PDF file is generated.
@param failure Block to be notified of failure.
*/
+ (BNHtmlPdfKit *)saveUrlAsPdf:(NSURL *)url toFile:(NSString *)filename pageSize:(BNPageSize)pageSize success:(void (^)(NSString *filename))completion failure:(void (^)(NSError *error))failure;
/**
Creates a BNHtmlPdfKit object to save a URL as a PDF file with BNPageSize, and landscape orientation.
@param url URL to save PDF of.
@param filename Filename to save file as.
@param pageSize BNPageSize of the page to be generated.
@param landscape Should the page be landscape.
@param completion Block to be notified when PDF file is generated.
@param failure Block to be notified of failure.
*/
+ (BNHtmlPdfKit *)saveUrlAsPdf:(NSURL *)url toFile:(NSString *)filename pageSize:(BNPageSize)pageSize isLandscape:(BOOL)landscape success:(void (^)(NSString *filename))completion failure:(void (^)(NSError *error))failure;
/**
Creates a BNHtmlPdfKit object to save a URL as a PDF file with BNPageSize, landscape orientation, and margin sizes.
@param url URL to save PDF of.
@param pageSize BNPageSize of the page to be generated.
@param landscape Should the page be landscape.
@param topAndBottom Top and bottom margin size.
@param leftAndRight Left and right margin size.
@param completion Block to be notified when PDF file is generated.
@param failure Block to be notified of failure.
*/
+ (BNHtmlPdfKit *)saveUrlAsPdf:(NSURL *)url toFile:(NSString *)filename pageSize:(BNPageSize)pageSize isLandscape:(BOOL)landscape topAndBottomMarginSize:(CGFloat)topAndBottom leftAndRightMarginSize:(CGFloat)leftAndRight success:(void (^)(NSString *filename))completion failure:(void (^)(NSError *error))failure;
/**
Creates a BNHtmlPdfKit object to save a URL as PDF with custom page size..
@param url URL to save PDF of.
@param pageSize CGSize of the page to be generated.
@param completion Block to be notified when PDF file is generated.
@param failure Block to be notified of failure.
*/
+ (BNHtmlPdfKit *)saveUrlAsPdf:(NSURL *)url customPageSize:(CGSize)pageSize success:(void (^)(NSData *pdfData))completion failure:(void (^)(NSError *error))failure;
/**
Creates a BNHtmlPdfKit object to save a URL as PDF with custom page size.
@param url URL to save PDF of.
@param pageSize CGSize of the page to be generated.
@param topAndBottom Top and bottom margin size.
@param leftAndRight Left and right margin size.
@param completion Block to be notified when PDF data is generated.
@param failure Block to be notified of failure.
*/
+ (BNHtmlPdfKit *)saveUrlAsPdf:(NSURL *)url customPageSize:(CGSize)pageSize topAndBottomMarginSize:(CGFloat)topAndBottom leftAndRightMarginSize:(CGFloat)leftAndRight success:(void (^)(NSData *pdfData))completion failure:(void (^)(NSError *error))failure;
/**
Creates a BNHtmlPdfKit object to save a URL as PDF with custom page size.
@param url URL to save PDF of.
@param filename Filename to save file as.
@param pageSize CGSize of the page to be generated.
@param completion Block to be notified when PDF data is generated.
@param failure Block to be notified of failure.
*/
+ (BNHtmlPdfKit *)saveUrlAsPdf:(NSURL *)url toFile:(NSString *)filename customPageSize:(CGSize)pageSize success:(void (^)(NSString *filename))completion failure:(void (^)(NSError *error))failure;
/**
Creates a BNHtmlPdfKit object to save a URL as PDF with BNPageSize.
@param url URL to save PDF of.
@param filename Filename to save file as.
@param pageSize CGSize of the page to be generated.
@param topAndBottom Top and bottom margin size.
@param leftAndRight Left and right margin size.
@param completion Block to be notified when PDF file is generated.
@param failure Block to be notified of failure.
*/
+ (BNHtmlPdfKit *)saveUrlAsPdf:(NSURL *)url toFile:(NSString *)filename customPageSize:(CGSize)pageSize topAndBottomMarginSize:(CGFloat)topAndBottom leftAndRightMarginSize:(CGFloat)leftAndRight success:(void (^)(NSString *filename))completion failure:(void (^)(NSError *error))failure;
/**
Initializes BNHtmlPdfKit with a BNPageSize.
@param pageSize The page size the output should be at.
@return An initialized `BNHtmlPdfKit` object.
*/
- (id)initWithPageSize:(BNPageSize)pageSize;
/**
Initializes BNHtmlPdfKit with a BNPageSize.
@param pageSize The page size the output should be at.
@param landscape Should the page be printed in landscape?
@return An initialized `BNHtmlPdfKit` object.
*/
- (id)initWithPageSize:(BNPageSize)pageSize isLandscape:(BOOL)landscape;
/**
Initializes BNHtmlPdfKit with a custom page size.
@param pageSize The page size the output should be at.
@return An initialized `BNHtmlPdfKit` object.
*/
- (id)initWithCustomPageSize:(CGSize)pageSize;
/**
Get a CGSize of what the BNPageSize represents.
@param pageSize Page Size to get the CGSize of.
*/
+ (CGSize)sizeForPageSize:(BNPageSize)pageSize;
/**
The size of the paper to print on.
*/
- (CGSize)actualPageSize;
/**
Saves an html string to PDF data.
@param html The HTML to save as a pdf.
*/
- (void)saveHtmlAsPdf:(NSString *)html;
/**
Saves an html string to a PDF file.
@param html The HTML to save as a pdf file.
@param file The filename of the pdf file to save.
*/
- (void)saveHtmlAsPdf:(NSString *)html toFile:(NSString *)file;
/**
Saves an html string to PDF data.
@param url The URL to save as a pdf.
*/
- (void)saveUrlAsPdf:(NSURL *)url;
/**
Saves an html string to a PDF file.
@param url The URL to save as a pdf file.
@param file The filename of the pdf file to save.
*/
- (void)saveUrlAsPdf:(NSURL *)url toFile:(NSString *)file;
/**
Saves an webView to PDF data.
@param webView The webView to save as a pdf.
*/
- (void)saveWebViewAsPdf:(UIWebView *)webView;
/**
Saves webView content to a PDF file.
@param webView The webView to save as a pdf file.
@param file The filename of the pdf file to save.
*/
- (void)saveWebViewAsPdf:(UIWebView *)webView toFile:(NSString *)file;
/**
Determine the preferred paper size for general printing. From Pierre Bernard.
@return paper size (currently: A4 or Letter).
*/
+ (BNPageSize)defaultPageSize;
@end;
/**
The `BNHtmlPdfKitDelegate` protocol defines methods that a delegate of a `BNHtmlPdfKit` object that provides feedback
based on the operations being performed.
*/
@protocol BNHtmlPdfKitDelegate <NSObject>
@optional
/**
Sent when pdf data has been generated.
@param htmlPdfKit The `BNHtmlPdfKit` that data is being saved from.
@param data The PDF data that was created from HTML/URL.
*/
- (void)htmlPdfKit:(BNHtmlPdfKit *)htmlPdfKit didSavePdfData:(NSData *)data;
/**
Sent when pdf data has been generated.
@param htmlPdfKit The `BNHtmlPdfKit` that data is being saved from.
@param data The PDF data that was created from HTML/URL.
*/
- (void)htmlPdfKit:(BNHtmlPdfKit *)htmlPdfKit didSavePdfFile:(NSString *)file;
/**
Sent when there was an error trying to generate the PDF.
@param htmlPdfKit The `BNHtmlPdfKit` that theerror generated from.
*/
- (void)htmlPdfKit:(BNHtmlPdfKit *)htmlPdfKit didFailWithError:(NSError *)error;
@end;