title: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 162: invalid start byte
body: <p>I am fetching data from s3 and I need to extract the text from a pdf file.</p>
  <pre><code>import boto3
  
  from io import StringIO
  from pdfminer.converter import TextConverter
  from pdfminer.layout import LAParams
  from pdfminer.pdfdocument import PDFDocument
  from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
  from pdfminer.pdfpage import PDFPage
  from pdfminer.pdfparser import PDFParser
  
  s3_client = boto3.client('s3')
  s3_bucket_name = 'XXXXXX'
  s3 = boto3.resource('s3',
                      aws_access_key_id = 'XXXXXXXX',
                      aws_secret_access_key='XXXXXXX')
  
  obj = s3.Object(s3_bucket_name, 'XXXXXX.pdf').get()
  data = obj['Body'].read()
  
  output_string = StringIO()
  with open(data, 'rb') as in_file:
      parser = PDFParser(in_file)
      doc = PDFDocument(parser)
      rsrcmgr = PDFResourceManager()
      device = TextConverter(rsrcmgr, output_string, laparams=LAParams())
      interpreter = PDFPageInterpreter(rsrcmgr, device)
      for page in PDFPage.create_pages(doc):
          interpreter.process_page(page)
  
  print(output_string.getvalue())
  </code></pre>
  <p>I'm getting this error:</p>
  <p>with open(data, 'rb') as in_file:
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 162: invalid start byte</p>