Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to include image in PDF from HTML after updating web-view on iOS #109

Closed
askulikov opened this issue Oct 30, 2019 · 1 comment · Fixed by #123
Closed

Impossible to include image in PDF from HTML after updating web-view on iOS #109

askulikov opened this issue Oct 30, 2019 · 1 comment · Fixed by #123

Comments

@askulikov
Copy link

After updating cordova-plugin-ionic-webview to 4.1.1 it is impossible to include images in pdf.
All paths is not resolved. I spend about 3 days, trying find right path, but unsuccessfully.
Diving deeper in native source of plugin, i found that base url will be empty string:
PDFGenerator.m:137

if (data != NULL){
  NSURL *base =  [[NSURL alloc] initWithString:[[self.webViewEngine.URL absoluteString] stringByDeletingLastPathComponent]];
  // self.webViewEngine.URL === 'ionic://localhost'
  self.htmlPdfKit = [BNHtmlPdfKit saveHTMLAsPdf:data
                                  pageSize:pageSize
                                  isLandscape:landscape
		                  baseUrl:base
                                  success:[self GetPDFHandler:command setOptions:option]
                                  failure:[self GetErrorHandler:command]];
    
        
  NSLog(@"url--> %@", [[base absoluteString] stringByDeletingLastPathComponent]); // output is 'url--> '
}

At this time output of self.webViewEngine.URL will be ionic://localhost.
Unfortunately i'm not familiar in native code, but diving deeper in code, i found this in BNHtmlPdfKit.m:371 :

- (void)saveHtmlAsPdf:(NSString *)html toFile:(NSString *)file {
    self.outputFile = file;
    
    self.webView = [[WKWebView alloc] init];
    self.webView.navigationDelegate = self;
    
    if (!self.baseUrl) {
        [self.webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://localhost"]];
    } else {
        [self.webView loadHTMLString:html baseURL:self.baseUrl];
    }
}

As i understand, !self.baseUrl === true, and it pass first if-case, where for baseUrl will be assigned http://localhost. And i think it may crash all process.

Anyway, i'm not sure about my previous assumptions, but putting in PDFGenerator.m:143
baseUrl:[[NSBundle mainBundle] bundleURL] instead of baseUrl:base solve this problem.

Hope, it will save some time for somebody.

@lucashsilva
Copy link
Contributor

I confirm this works. It would be nice to get an update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants