Q: Encoding issues during the extraction text from pdf file using pdfplumber I would like to extract the content of the following pdf file but it returns a meaningless result. I assume that it might be related to the encoding side of the file but the same extraction code works for many other files on the same infrastructure. This is not a single file which does not handled by the following script, there are some other cases as well. However, I have only placed here an example. I realized that if I copy/paste the text content of this file to my notepad, it is not properly pasted as well. The pasted text is not that bad I placed it at the bottom but it is not acceptable as well.
How should I approach to this problem? Any suggestions ?
#  -*- coding: utf-8 -*-
import urllib3
import pdfplumber
import io

def extract_text_from_pdf_by_url(url):
    all_text = ''

    http = urllib3.PoolManager()
    temp = io.BytesIO()
    temp.write(http.request("GET", url).data)
    try:    # to verify is the url has valid pdf file!
        pdf = pdfplumber.open(temp)
        for pdf_page in pdf.pages:
            single_page_text = pdf_page.extract_text()
            # TypeError: can only concatenate str (not "NoneType") to str
            if single_page_text is not None: 
                all_text += '\n' + single_page_text
        pdf.close()
    except:
        pass
    return all_text


url  = '4yM2t3s0uI33S.pdf'
text = extract_text_from_pdf_by_url(url)
print(text)

It returns:

Şİİİıı  ı İİİ İıŞİ
ıöö ç ıı    ııçıı  öİ ı ıçıüüışü   üüğöüüıışı
ıİÖıİ
ö ıüö ıöğğ ı ç şüıııııı ş
...

