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

View File

@ -73,10 +73,19 @@ class CLData:
if result.returncode == 0: if result.returncode == 0:
print(build_text + "[SUCCESS]") 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( 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, stdout=subprocess.PIPE,
text=True text=True
) )