I have string representing a PDF that I'd like to save as a pdf file, my problem is that saving this string to a file results in a pdf with blank pages.
I've tried encoding the string as 'utf-8' and saving the bytes to a file but this results in the same issue.
import requests
url = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf'
response = requests.get(url)
with open('example.pdf', 'w') as f:
f.write(response.text)
I'm aware that saving response.content
is the correct way to save the pdf in the example above, but in my particular use case I only have access to the string