Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jeremygradisher opened this issue Jan 9, 2024 · 7 comments

Comments

@jeremygradisher
Copy link

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

  • the way I generate this uses a render_to_string() to create and save a document to an S3 bucket. I see no reason that would matter here but the following is part of how I am doing it:
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
Copy link
Collaborator

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
Copy link
Author

It does:
Screenshot 2024-01-09 at 4 29 55 PM

@unixmonkey
Copy link
Collaborator

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: #830 (comment)

@jeremygradisher
Copy link
Author

jeremygradisher commented Jan 11, 2024

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
Copy link

clementf commented Apr 4, 2024

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

@jeremygradisher
Copy link
Author

jeremygradisher commented Apr 8, 2024

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants