Safi Ullah
Safi Ullah

Reputation: 1

Download pdf in Japanese shows garbled text on production for rails application using Wickedpdf gem, working perfectly fine locally

Here is the issue in the screenshot Output

I have tried multiple things:

  1. I have tried to download the Japanese fonts locally on the production server
  2. Added this in the pdf layout:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <style type="text/css">
    @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP&display=swap');
    body {
      font-family: 'Noto Sans JP', sans-serif;
    }
  </style>
</head>
<body>
  <%= yield %>
</body>
</html>

  1. Added this in the pdf.scss

@font-face {
      font-family: 'Noto Sans CJK';
      src: url('<%= asset_path("NotoSansCJK-wght-400-900.ttf.woff2") %>') format('woff2'),
        url('<%= asset_path("NotoSansCJK-wght-400-900.ttf.ttc") %>') format('truetype-    collection');
      font-weight: 400;
      font-style: normal;
    }

    @font-face {
      font-family: 'Noto Serif CJK';
       src: url('<%= asset_path("NotoSerifCJK-wght-400-900.ttf.woff2") %>') format('woff2'),
         url('<%= asset_path("NotoSerifCJK-wght-400-900.ttf.ttc") %>') format('truetype-collection');
      font-weight: 400;
      font-style: normal;
    }

  1. Added in the initializer for assets:

Rails.application.config.assets.precompile += %w( bootstrap.min.js popper.js pdf.scss .woff2 .ttc .svg .eot .woff .ttf )

  1. Also tried to add google apis for fonts

All these methods didn't work as expected in the production environment, using Ubuntu there.

Upvotes: 0

Views: 34

Answers (0)

Related Questions