@@ -52,7 +52,7 @@ @implementation RNHTMLtoPDF {
52
52
UIColor *_bgColor;
53
53
NSInteger *_numberOfPages;
54
54
CGSize _PDFSize;
55
- UIWebView *_webView;
55
+ WKWebView *_webView;
56
56
float _paddingBottom;
57
57
float _paddingTop;
58
58
float _paddingLeft;
@@ -73,8 +73,8 @@ + (BOOL)requiresMainQueueSetup
73
73
- (instancetype )init
74
74
{
75
75
if (self = [super init ]) {
76
- _webView = [[UIWebView alloc ] initWithFrame: self .bounds];
77
- _webView.delegate = self;
76
+ _webView = [[WKWebView alloc ] initWithFrame: self .bounds];
77
+ _webView.navigationDelegate = self;
78
78
[self addSubview: _webView];
79
79
autoHeight = false ;
80
80
}
@@ -173,44 +173,43 @@ - (instancetype)init
173
173
174
174
NSString *path = [[NSBundle mainBundle ] bundlePath ];
175
175
NSURL *baseURL = [NSURL fileURLWithPath: path];
176
-
177
- [_webView loadHTMLString: _html baseURL: baseURL];
176
+ dispatch_async (dispatch_get_main_queue (), ^{
177
+ [_webView loadHTMLString: _html baseURL: baseURL];
178
+ });
178
179
179
180
_resolveBlock = resolve;
180
181
_rejectBlock = reject;
181
182
182
183
}
183
-
184
- - (void )webViewDidFinishLoad : (UIWebView *)awebView
185
- {
186
- if (awebView.isLoading )
187
- return ;
188
-
184
+ -(void )webView : (WKWebView *)webView didFinishNavigation : (WKNavigation *)navigation {
185
+ if (webView.isLoading )
186
+ return ;
187
+
189
188
UIPrintPageRenderer *render = [[UIPrintPageRenderer alloc ] init ];
190
- [render addPrintFormatter: awebView .viewPrintFormatter startingAtPageAtIndex: 0 ];
191
-
189
+ [render addPrintFormatter: webView .viewPrintFormatter startingAtPageAtIndex: 0 ];
190
+
192
191
// Define the printableRect and paperRect
193
192
// If the printableRect defines the printable area of the page
194
193
CGRect paperRect = CGRectMake (0 , 0 , _PDFSize.width , _PDFSize.height );
195
194
CGRect printableRect = CGRectMake (_paddingTop, _paddingLeft, _PDFSize.width -(_paddingLeft + _paddingRight), _PDFSize.height -(_paddingBottom + _paddingTop));
196
-
197
-
195
+
196
+
198
197
[render setValue: [NSValue valueWithCGRect: paperRect] forKey: @" paperRect" ];
199
198
[render setValue: [NSValue valueWithCGRect: printableRect] forKey: @" printableRect" ];
200
-
199
+
201
200
NSData * pdfData = [render printToPDF: &_numberOfPages backgroundColor: _bgColor ];
202
-
201
+
203
202
if (pdfData) {
204
203
NSString *pdfBase64 = @" " ;
205
-
204
+
206
205
[pdfData writeToFile: _filePath atomically: YES ];
207
206
if (_base64) {
208
207
pdfBase64 = [pdfData base64EncodedStringWithOptions: 0 ];
209
208
}
210
209
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
211
- pdfBase64, @" base64" ,
212
- [NSString stringWithFormat: @" %ld " , (long )_numberOfPages], @" numberOfPages" ,
213
- _filePath, @" filePath" , nil ];
210
+ pdfBase64, @" base64" ,
211
+ [NSString stringWithFormat: @" %ld " , (long )_numberOfPages], @" numberOfPages" ,
212
+ _filePath, @" filePath" , nil ];
214
213
_resolveBlock (data);
215
214
} else {
216
215
NSError *error;
0 commit comments