Call gs directly when compressing PDFs.

I.e. avoid unnecessary bash invocation.
This commit is contained in:
Sage Vaillancourt 2022-09-27 08:32:32 -04:00
parent 13781ba7d9
commit cfcd318011
2 changed files with 14 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import types
import json
class MockConnection:
mock_cursor = types.SimpleNamespace()
mock_cursor.execute = lambda *a: ()
@ -21,7 +22,8 @@ class MockConnection:
class MockCreator:
def create(self, data=None, *a):
@staticmethod
def create(data=None, *a):
print(json.JSONEncoder(indent=2).encode(data))
result = types.SimpleNamespace()
result.status_code = 200

View File

@ -73,10 +73,19 @@ class CLData:
if result.returncode == 0:
print(build_text + "[SUCCESS]")
compress_com = "gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dNOPAUSE -dQUIET -dBATCH -dPrinted=false -sOutputFile=outputs/" + unique_id + ".compressed.pdf outputs/" + unique_id + ".pdf"
result = subprocess.run(
['bash', '-c', compress_com],
[
'gs'
'-sDEVICE=pdfwrite'
'-dCompatibilityLevel=1.5'
'-dNOPAUSE'
'-dQUIET'
'-dBATCH'
'-dPrinted=false'
'-sOutputFile=outputs/' + unique_id + '.compressed.pdf',
'outputs/' + unique_id + '.pdf'
],
stdout=subprocess.PIPE,
text=True
)