christopherdro / react-native-html-to-pdf

Convert html strings to PDF documents using React Native
MIT License
434 stars 264 forks source link

Script is not working with attached HTML (Chart) #239

Closed VikasSahu closed 2 years ago

VikasSahu commented 2 years ago

Hello

I want to have a line chart and bar chart in my generated PDF but somehow script is not working with attached HTML.

I am using below chart script in my HTML code (only script part is here, its Incomplete code)

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<body>
<canvas id="myChart" style="width:100%;max-width:600px"></canvas>
<script>var xValues=["Italy","France","Spain","USA","Argentina"];var yValues=[55,49,44,24,15];var barColors=["red","green","blue","orange","brown"];new Chart("myChart",{type:"bar",data:{labels:xValues,datasets:[{backgroundColor:barColors,data:yValues}]},options:{legend:{display:false},title:{display:true,text:"World Wine Production 2018"}}});</script>

Could please help, how to achieve that?

zhani-tegeria commented 2 years ago

Any solutions?

abhijit-jena21 commented 2 years ago

@VikasSahu Did you find any solution or workaround for this?

OmSingh5092 commented 2 years ago

Any Solutions?

suresh-jbt commented 2 years ago

I found the solution to enable js in web view.

suresh-jbt commented 2 years ago

After this line, you need to add: https://github.com/christopherdro/react-native-html-to-pdf/blob/master/android/src/main/java/android/print/PdfConverter.java#L114

settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);

To enabled js in web view.

I will generate PR for this issue

suresh-jbt commented 2 years ago

Here is the PR @VikasSahu @OmSingh5092 @abhijit-jena21 @zhani-tegeria

OmSingh5092 commented 2 years ago

Hey @suresh-borad the script is functional but due to some reason the Chart is not visible in the pdf. Could this be because of the use of .

suresh-jbt commented 2 years ago

Hey @suresh-borad the script is functional but due to some reason the Chart is not visible in the pdf. Could this be because of the use of.

Yes, @OmSingh5092 I had the same issue with android and I'm using Google Chart lib in HTML. After these changes, it's working fine.

The iOs was working fine without any changes but the issue with android.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

jpn918 commented 1 year ago
code

Does this Githubissues.

  • Githubissues is a development platform for aggregating issues.