Convert metadata key/value to a form that hyperref accepts.
(key, value)
| 147 | |
| 148 | |
| 149 | def _metadata_to_str(key, value): |
| 150 | """Convert metadata key/value to a form that hyperref accepts.""" |
| 151 | if isinstance(value, datetime.datetime): |
| 152 | value = _datetime_to_pdf(value) |
| 153 | elif key == 'Trapped': |
| 154 | value = value.name.decode('ascii') |
| 155 | else: |
| 156 | value = str(value) |
| 157 | |
| 158 | # ensure that metadata does not contain special TeX chars because we |
| 159 | # insert the metadata as raw text into the TeX source |
| 160 | invalid_chars = r"\{}[]()" |
| 161 | if any(c in value + key for c in invalid_chars): |
| 162 | raise ValueError( |
| 163 | f"Invalid metadata value for {key!r}: {value!r}. " |
| 164 | f"The value must not contain the chars {invalid_chars}.") |
| 165 | |
| 166 | return f'{key}={{{value}}}' |
| 167 | |
| 168 | |
| 169 | def make_pdf_to_png_converter(): |
searching dependent graphs…