mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.52k stars 640 forks source link

Greek Character "𝛼" not showing correctly within PDF generated by Wicked PDF #1095

Open jeremygradisher opened 5 months ago

jeremygradisher commented 5 months ago

I can get the Greek Character "𝛼" to show on a page:

alpha-showing-on-page

But when I generate a doc using Wicked_PDF, it doesn't show up correctly.

alpha-character-bad-wicked-pdf

Does anyone have an idea of how to resolve this? I have tried multiple fonts to troubleshoot if I were using one without font-support for the greek letters, but that does not appear to be the issue.

css

body, html {
    font-family: "Arial Unicode MS", sans-serif;
}

Further details

s3 = Aws::S3::Resource.new(region: ENV['S3_REGION'])
      obj = s3.bucket(ENV['S3_BUCKET_NAME']).object(document_filename)
      obj.put(body: render_to_string(
          pdf: document_filename,
          template: "factory/_lorem",
          formats: [:html, :pdf],
          layout: "pdf_layout",
          page_size: 'Letter',
          encoding: 'utf8',
          javascript_delay: 1000,
          header: {
              html: {
                  template: "documents/pdf_header",
                  formats: [:pdf]
              }
          },
          footer: {
              html: {
                  template: "documents/pdf_footer",
                  formats: [:pdf]
              }
          }
      ))

      # Create a Document record
      Document.create(
        user: current_user, 
        account: current_user.account, 
        s3_key: document_filename,
        factory_id: factorydoc_id,        # Set factory_id from the URL parameter
        name: compound_name               # Set name from the compound's name in @factorydoc
      )

      redirect_to factory_index_path, notice: 'Document generated successfully!'

What gets sent through that render_to_string is this:

latex

latex: "OEL = \\frac{PoD\\left ( \\frac{mg}{kg/day} \\right ) \\times BW (kg)}{AF\\times SS \\times \\alpha \\times Vol }"

Here, \\alpha is the LaTeX command for the alpha symbol. When rendered correctly, this should display the Greek letter alpha (𝛼).


wicked_pdf gem version: wicked_pdf (2.7.0)

wkhtmltopdf version: wkhtmltopdf 0.12.6 (with patched qt)

platform/distribution and version: Ruby on Rails 7 -

unixmonkey commented 5 months ago

Can you verify that your HTML that gets converted has this in the <head>, like is suggested here in the README?

<meta charset='utf-8' />
jeremygradisher commented 5 months ago

It does:

Screenshot 2024-01-09 at 4 29 55 PM
unixmonkey commented 5 months ago

Ok, then it must not be a supported glyph in your system fonts (on the server that actually generates the PDF).

You may need to install system font packages on your linux servers with something like yum install freetype fontconfig or specifically embed a font that you know has those glyphs as described here: https://github.com/mileszs/wicked_pdf/issues/830#issuecomment-487578079

jeremygradisher commented 5 months ago

I am working on embedding a font to keep this consistent across users and across dev, production and within the documents generated, but I do want to point out, within the PDF document calculations, that Alpha symbol "𝛼" is showing up. But then in the variables table it does not. alpha-symbol

If you look at the way I am rendering this to string w render_to_string, you will see it is done with KaTex using \\alpha within the calculation, and just using the symbol "𝛼" within the table.

Screenshot 2024-01-11 at 11 25 28 AM

Again, I am following up with embedding a font into my Rails application that I can prove supports the "𝛼" Alpha greek character to see if that resolves it. I will update once I have it resolved to state what the fix is.

clementf commented 2 months ago

Hey @jeremygradisher, I'm running into a similar issue with the pi symbol, any chance you found something that worked for you?

jeremygradisher commented 2 months ago

@clementf What I was getting here to print was coming from an API. We solved this by getting that symbol to be sent like this \u003E&alpha;\u003C from the API as opposed to \u003E𝛼\u003C which unfortunately probably does not help you here.

clementf commented 2 months ago

Thanks @jeremygradisher for the help! In the end we're also going to solve it with a workaround for the time being.