┌──────────────────────────────────────────────────────────┐ │ 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")
| 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 │ |
| 829 | │ as 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 |
no test coverage detected