title: UnicodeEncodeError: 'latin-1' codec can't encode character '\u2013' (writing to PDF)
body: <p>I am having an issue with <code>Unicode</code> with a variable contents when writing to a .pdf with python.</p>
  
  <p><strong>It's outputting this error:</strong> </p>
  
  <pre><code>UnicodeEncodeError: 'latin-1' codec can't encode character '\u2013'
  </code></pre>
  
  <p>Which is it getting caught on an em dash basically. </p>
  
  <p>I have tried taking that variable, where the contents has an 'em dash' and redefined it with an '<code>.encode('utf-8')</code>' for example, i.e., below:</p>
  
  <pre><code>Body = msg.Body
  
  BodyC = Body.encode('utf-8')
  </code></pre>
  
  <p>And now I get the <strong>below error:</strong></p>
  
  <pre><code>Traceback (most recent call last):
    File "script.py", line 37, in &lt;module&gt;
      pdf.cell(200, 10, txt="Bod: " + BodyC,  ln=4, align="C")
  TypeError: can only concatenate str (not "bytes") to str
  </code></pre>
  
  <p>Below is my full code, how could I simply fix my Unicode error in '<code>Body</code>' variable contents. </p>
  
  <p>Converting to <code>utf-8</code> or <code>western</code>, anything outside of '<code>latin-1</code>'. Any suggestions?</p>
  
  <p><strong>Full Code:</strong></p>
  
  <pre><code>from fpdf import FPDF
  import win32com.client
  
  outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
  msg = outlook.OpenSharedItem(r"C:\User\language\python\Msg-To-PDF\test_msg.msg")
  
  print (msg.SenderName)
  print (msg.SenderEmailAddress)
  print (msg.SentOn)
  print (msg.To)
  print (msg.CC)
  print (msg.BCC)
  print (msg.Subject)
  print (msg.Body)
  
  SenderName = msg.SenderName
  SenderEmailAddress = msg.SenderEmailAddress
  SentOn = msg.SentOn
  To = msg.To
  CC = msg.CC
  BCC = msg.BCC
  Subject = msg.Subject
  Body = msg.Body
  BodyC = Body.encode('utf-8')
  
  pdf = FPDF()
  pdf.add_page()
  
  # pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True)
  pdf.set_font("Helvetica", style = '', size = 11)
  pdf.cell(200, 10, txt="From: " + SenderName, ln=1, align="C")
  # pdf.cell(200, 10, border=SentOn, ln=1, align="C")
  pdf.cell(200, 10, txt="To: " + To, ln=1, align="C")
  pdf.cell(200, 10, txt="CC: " + CC, ln=1, align="C")
  pdf.cell(200, 10, txt="BCC: " + BCC, ln=1, align="C")
  pdf.cell(200, 10, txt="Subject: " + Subject, ln=1, align="C")
  pdf.cell(200, 10, txt="Bod: " + BodyC,  ln=4, align="C")
  
  pdf.output("Sample.pdf")
  </code></pre>
  
  <ul>
  <li><strong>How can I change out of <code>'latin1'</code>?</strong></li>
  </ul>
  
  <hr>
  
  <ul>
  <li>Anyway to just globally fix these issues?</li>
  </ul>
  
  <hr>