def get_formatted_content(pdf_content):
    cmd = 'pdftocairo -pdf - -'
ps = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = ps.communicate(input=pdf_content)
if ps.returncode != 0:
    raise OSError(ps.returncode, cmd, stderr)
return stdout
How to get the diff of two PDF files in python?