Skip to content

Instantly share code, notes, and snippets.

@Cykooz
Created June 1, 2021 06:35
Show Gist options
  • Save Cykooz/3c642391af4f79318331bd826dd48f53 to your computer and use it in GitHub Desktop.
Save Cykooz/3c642391af4f79318331bd826dd48f53 to your computer and use it in GitHub Desktop.
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