cesarvr / pdf-generator

Cordova plugin to generate pdf in the client-side
MIT License
107 stars 61 forks source link

iOS - Links to CSS don't work #59

Open wnbittle opened 6 years ago

wnbittle commented 6 years ago

I'm having an issue when sending the plugin an HTML string with link elements in iOS.

On Android, I was not able to get relative paths to work either, however, I was able to rewrite the relative paths to full paths using cordova.file.applicationDirectory/www/[relative path] to make them work.

On iOS, this doesn't work. I've tried relative paths, absolute paths, and many other variations without success. Finally, I decided to debug the linked BNHtmlPdfKit.m source, I noticed that the self.baseUrl property is nil, and as a result, it uses http://localhost for the baseUrl of the webview see here. If I set self.baseUrl to [[NSBundle mainBundle] bundleURL], the relative paths work. I'm guessing that the method you added was this which could be edited to set the self.baseUrl via a configuration property from javascript.

Would you be able to expose a baseUrl property in the configuration object to set this property? I can submit a pull request, but this seemed like a pretty quick/easy change.

Thanks, William

wnbittle commented 6 years ago

Quick update with clarification:

Relative paths to CSS + HTML string do not work. Relative paths to CSS + HTML string along with setting the baseUrl to the bundleURL do not work Full paths to CSS + HTML string along with setting the baseUrl to the bundleURL do work.

smart548 commented 6 years ago

@wnbittle

Can I ask you to help me there too?

https://github.com/cesarvr/pdf-generator/issues/80

Many thanks.

Chousse commented 5 years ago

Hi everyone, seems this issue always here, I can't link images or css with ios. On android I have an other weird issue, it saving me a PDF with an asset per page