8000 Implement PDF metadata on PGF backend. · matplotlib/matplotlib@390e438 · GitHub
[go: up one dir, main page]

Skip to content

Commit 390e438

Browse files
committed
Implement PDF metadata on PGF backend.
This is supported through the multipage PdfPages, but not direct output of a single figure via PGF.
1 parent 28cbef0 commit 390e438

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/matplotlib/backends/backend_pgf.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,13 @@ def print_pgf(self, fname_or_fh, *args, **kwargs):
868868
file = codecs.getwriter("utf-8")(file)
869869
self._print_pgf_to_fh(file, *args, **kwargs)
870870

871-
def _print_pdf_to_fh(self, fh, *args, **kwargs):
871+
def _print_pdf_to_fh(self, fh, *args, metadata=None, **kwargs):
872872
w, h = self.figure.get_figwidth(), self.figure.get_figheight()
873873

874+
info_dict = _create_pdf_info_dict('pgf', metadata or {})
875+
hyperref_options = ','.join(
876+
f'{k}={{{v}}}' for k, v in info_dict.items())
877+
874878
try:
875879
# create temporary directory for compiling the figure
876880
tmpdir = tempfile.mkdtemp(prefix="mpl_pgf_")
@@ -884,6 +888,8 @@ def _print_pdf_to_fh(self, fh, *args, **kwargs):
884888
latex_preamble = get_preamble()
885889
latex_fontspec = get_fontspec()
886890
latexcode = """
891+
\\PassOptionsToPackage{pdfinfo={%s}}{hyperref}
892+
\\RequirePackage{hyperref}
887893
\\documentclass[12pt]{minimal}
888894
\\usepackage[paperwidth=%fin, paperheight=%fin, margin=0in]{geometry}
889895
%s
@@ -893,7 +899,7 @@ def _print_pdf_to_fh(self, fh, *args, **kwargs):
893899
\\begin{document}
894900
\\centering
895901
\\input{figure.pgf}
896-
\\end{document}""" % (w, h, latex_preamble, latex_fontspec)
902+
\\end{document}""" % (hyperref_options, w, h, latex_preamble, latex_fontspec)
897903
pathlib.Path(fname_tex).write_text(latexcode, encoding="utf-8")
898904

899905
texcommand = mpl.rcParams["pgf.texsystem"]

0 commit comments

Comments
 (0)
0