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

writehtml Turkish Character Error #1281

Open
mglnr opened this issue Oct 10, 2024 · 8 comments
Open

writehtml Turkish Character Error #1281

mglnr opened this issue Oct 10, 2024 · 8 comments

Comments

@mglnr
Copy link

mglnr commented Oct 10, 2024

Hello,

I'm testing with writehtml at https://py-pdf.github.io/fpdf2/HTML.html. Unfortunately, I could not run the application when I used Turkish characters in my test. The application does not open when you type the characters "ğĞİÖÖüÜ". I added add_font with external Turkish character support, but the problem persists.

@mglnr mglnr added the bug label Oct 10, 2024
@Lucas-C
Copy link
Member

Lucas-C commented Oct 11, 2024

Hi @mglnr

I'd be happy to try to help you, but the information you provided is not precise enough to be able to solve your problem.

Could you please provide some minimal code reproducing your problem: https://stackoverflow.com/help/minimal-reproducible-example

Also, what do you mean by "The application does not open"?

Do you get an error when running your Python script?

Or is it that you cannot open the PDF file produced?

At this point, I can only guess that the font file you provided (the "external Turkish character support") simply does not render the characters ğĞİÖÖüÜ

@mglnr
Copy link
Author

mglnr commented Oct 14, 2024

Thank you for your interest. When I type one of the characters "ğĞİÖÖÜÜ" and run my test application, the application closes without creating the pdf. When I use only the characters I specified, the situation I specified occurs.

@Lucas-C
Copy link
Member

Lucas-C commented Oct 14, 2024

When I type one of the characters "ğĞİÖÖÜÜ" and run my test application, the application closes without creating the pdf.

Do you have any error produced?

If the call to .output() fails to create a file, you should probably have an error raised.

If so, could you please share the stacktrace?

Otherwise there is really not much I can do to help you...

@andersonhc
Copy link
Collaborator

@mglnr Here is a small test I did showing fpdf2 can handle the characters if you are using a compatible font:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.add_font(family="Noto", fname="NotoSans-Regular.ttf")
pdf.set_font("Noto", "", 16)
pdf.write_html("""
  <h1>ğĞİÖÖÜÜ</h1>
""")
pdf.output("issue1281.pdf")

I really don't know how to help you any further without specific information about your code and the error you are getting.

@mglnr
Copy link
Author

mglnr commented Oct 15, 2024

"ğĞİÖÖÜÜ" karakterlerinden birini yazıp test uygulamamı çalıştırdığımda pdf oluşturulmadan uygulama kapanıyor.

Herhangi bir hata oluştu mu?

Eğer çağrı .output()dosya oluşturmada başarısız olursa, muhtemelen bir hatayla karşılaşırsınız.

Eğer öyleyse, lütfen stacktrace'i paylaşabilir misiniz?

Aksi takdirde sana yardımcı olabileceğim pek bir şey yok...

I am sharing my test code below. I encounter an error when I use the characters ĞĞİÖÖÜÜ in the 14th line. My Test Code:

from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
pdf.add_font("Times New Roman", "", "times.ttf", uni=True)  # Normal font
pdf.add_font("Times New Roman", "B", "timesbd.ttf", uni=True)  # Kalın font
pdf.write_html("""
  <dl>
      <dt>Description title</dt>
      <dd>Description Detail</dd>
  </dl>
  <h1>Big title</h1>
    <p align="justify"><b>deneme</b>
      ğĞİÖÖüÜ deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme 
      deneme deneme deneme deneme deneme deneme deneme deneme 
      deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme 
      deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme deneme 
    </p>
    <br>
    <pre>i am preformatted text.</pre>
    <br>
    <blockquote>hello blockquote</blockquote>
    <table width="50%" border="1">
      <thead>
        <tr>
          <th width="30%">ID</th>
          <th width="70%">Name</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>1</td>
          <td>Alice</td>
        </tr>
        <tr>
          <td>2</td>
          <td>Bob</td>
        </tr>
      </tbody>
    </table>
""")
pdf.output("html.pdf")
input("pencereyi kapatma") 

``

@mglnr
Copy link
Author

mglnr commented Oct 15, 2024

@mglnr Here is a small test I did showing fpdf2 can handle the characters if you are using a compatible font:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.add_font(family="Noto", fname="NotoSans-Regular.ttf")
pdf.set_font("Noto", "", 16)
pdf.write_html("""
  <h1>ğĞİÖÖÜÜ</h1>
""")
pdf.output("issue1281.pdf")

I really don't know how to help you any further without specific information about your code and the error you are getting.

Thank you for your interest. When I changed the family to times-roman in the code you gave, the Turkish characters worked, but when I wrote the html table code below it, it did not work. Sample code:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.add_font(family="Times-Roman", fname="times.ttf")
pdf.set_font("Times-Roman", "", 12)
pdf.write_html("""
  <p align="justify"> deneme deneme </p>
    <table width="50%" border="1">
      <thead>
        <tr>
          <th width="30%">ID</th>
          <th width="70%">Name</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>1</td>
          <td>Alice</td>
        </tr>
        <tr>
          <td>2</td>
          <td>Bob</td>
        </tr>
      </tbody>
    </table>
""")
pdf.output("html.pdf")

input("Pencereyi kapatma.")

@andersonhc
Copy link
Collaborator

The default is table header being in bold and your code is failing because you didn't add a bold version of the font.

Add this line and your code should run OK:

pdf.add_font(family="Times-Roman", style="B", fname="timesbd.ttf")

@mglnr
Copy link
Author

mglnr commented Oct 15, 2024

The default is table header being in bold and your code is failing because you didn't add a bold version of the font.

Add this line and your code should run OK:

pdf.add_font(family="Times-Roman", style="B", fname="timesbd.ttf")

Thank you. I missed that detail.

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

No branches or pull requests

3 participants