1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-04 07:57:52 +03:00

Print pdf on errors

This commit is contained in:
Guillaume Ayoub 2020-12-12 15:59:31 +01:00
parent 29666609f4
commit 07e3673503

View File

@ -27,9 +27,10 @@ def document_write_png(self, target=None, resolution=96, antialiasing=1):
'gs', '-q', '-dNOPAUSE', '-dSAFER', f'-dTextAlphaBits={antialiasing}',
f'-dGraphicsAlphaBits={antialiasing}', '-sDEVICE=png16m',
f'-r{resolution}', '-sOutputFile=-', '-']
result = run(command, input=pdf, stdout=PIPE, stderr=PIPE)
result = run(command, input=pdf, stdout=PIPE)
pngs = result.stdout
print(repr(pdf))
assert pngs.startswith(MAGIC_NUMBER), (
'GhostScript error: '
f'{pngs.split(MAGIC_NUMBER)[0].decode("ascii").strip()}')
@ -43,7 +44,6 @@ def document_write_png(self, target=None, resolution=96, antialiasing=1):
else:
images = []
for i, png in enumerate(pngs[8:].split(MAGIC_NUMBER)):
print(result.stderr, pngs, png)
images.append(Image.open(io.BytesIO(MAGIC_NUMBER + png)))
width = max(image.width for image in images)