MCPcopy
hub / github.com/RUB-NDS/PRET / convert

Method convert

printer.py:823–844  ·  view source on GitHub ↗

┌──────────────────────────────────────────────────────────┐ │ Warning: ImageMagick and Ghostscript are used to convert │ │ the document to be printed into a language understood be │ │ the printer. Don't print anything from untrusted sources │ │ as it may be

(self, path, pdl="pcl")

Source from the content-addressed store, hash-verified

821
822 # convert image to page description language
823 def convert(self, path, pdl="pcl"):
824 """
825 ┌──────────────────────────────────────────────────────────┐
826 │ Warning: ImageMagick and Ghostscript are used to convert │
827 │ the document to be printed into a language understood be │
828 │ the printer. Don't print anything from untrusted sources │
829as it may be a security risk (CVE-2016–3714, 2016-7976). │
830 └──────────────────────────────────────────────────────────┘
831 """
832 try:
833 self.chitchat("Converting '" + path + "' to " + pdl + " format")
834 pdf = ["-density", "300"] if path.endswith(".pdf") else []
835 cmd = ["convert"] + pdf + [path, "-quality", "100", pdl + ":-"]
836 out, err = subprocess.PIPE, subprocess.PIPE
837 p = subprocess.Popen(cmd, stdout=out, stderr=err)
838 data, stderr = p.communicate()
839 except:
840 stderr = "ImageMagick or Ghostscript missing"
841 if stderr:
842 output().errmsg("Cannot convert", stderr)
843 else:
844 return data

Callers 2

do_printMethod · 0.95
do_overlayMethod · 0.80

Calls 3

chitchatMethod · 0.95
outputClass · 0.90
errmsgMethod · 0.80

Tested by

no test coverage detected