Created
June 1, 2021 06:35
-
-
Save Cykooz/3c642391af4f79318331bd826dd48f53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def get_pdf_first_page(executors_manager: ExecutorsManager, src_path, dst_path, *, dpi=72, png=False): | |
"""Try to get a first page of the given pdf-file with GS, ignoring all errors.""" | |
command = [ | |
'gs', | |
'-q', | |
f'-r{dpi}', | |
'-dTextAlphaBits=4', | |
'-dGraphicsAlphaBits=4', | |
] | |
if png: | |
command += [ | |
'-sDEVICE=png16m', | |
] | |
else: | |
command += [ | |
'-sDEVICE=jpeg', | |
'-dJPEGQ=85', | |
] | |
command += [ | |
'-dDOINTERPOLATE', | |
'-dSAFER', | |
'-dBATCH', | |
'-dNOPAUSE', | |
'-dFirstPage=1', | |
'-dLastPage=1', | |
f'-sOutputFile="{dst_path}"', | |
src_path, | |
] | |
stdout, stderr, code = await executors_manager.run_cpu_bounded_coroutine( | |
run_command, | |
command | |
) | |
return code, stderr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment