cesarvr / pdf-generator

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

Bad encoding for latin characters: é => é #12

Closed bdedardel closed 7 years ago

bdedardel commented 7 years ago

Hi,

I tried to generate pdf with some latin chars but without success:

In PDFGenerator.java

private void pdfPrinter(...)
if(args.getString(1) != null && !args.getString(1).equals("null")  ) 
  // webview.loadData(args.getString(1), "text/html", null);
  // NOK webview.loadData("Tést", "text/html", null); // => Tést
  webview.loadData("Tést", "text/html", "ISO-8859-1"); // => Tést

Any ideas ?

bdedardel commented 7 years ago

Solution found in: http://stackoverflow.com/questions/3961589/android-webview-and-loaddata

private void pdfPrinter(...) {
    ...
    if(args.getString(1) != null && !args.getString(1).equals("null")  ) {
        String content = 
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"+
        "<html><head>"+
        "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />"+
        "<head><body>";
    content += args.getString(1) + "</body></html>";
        // dont forget: charset=utf-8
        webview.loadData(content, "text/html; charset=utf-8", "UTF-8");
    }   
    ...
cesarvr commented 7 years ago

Hey thanks, I will take a look at it 👍

cesarvr commented 7 years ago

added utf-8 support https://github.com/cesarvr/pdf-generator/commit/57d40e5c6681a0031fab93eac9bf57d35fa7e821