Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 65ac78f

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 31e462b commit 65ac78f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

lib/matplotlib/backends/backend_pgf.py

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

884-
def _print_pdf_to_fh(self, fh, *args, **kwargs):
884+
def _print_pdf_to_fh(self, fh, *args, metadata=None, **kwargs):
885885
w, h = self.figure.get_figwidth(), self.figure.get_figheight()
886886

887+
info_dict = _create_pdf_info_dict('pgf', metadata or {})
888+
hyperref_options = ','.join(
889+
_metadata_to_str(k, v) for k, v in info_dict.items())
890+
887891
try:
888892
# create temporary directory for compiling the figure
889893
tmpdir = tempfile.mkdtemp(prefix="mpl_pgf_")
@@ -897,6 +901,8 @@ def _print_pdf_to_fh(self, fh, *args, **kwargs):
897901
latex_preamble = get_preamble()
898902
latex_fontspec = get_fontspec()
899903
latexcode = """
904+
\\PassOptionsToPackage{pdfinfo={%s}}{hyperref}
905+
\\RequirePackage{hyperref}
900906
\\documentclass[12pt]{minimal}
901907
\\usepackage[paperwidth=%fin, paperheight=%fin, margin=0in]{geometry}
902908
%s
@@ -906,7 +912,7 @@ def _print_pdf_to_fh(self, fh, *args, **kwargs):
906912
\\begin{document}
907913
\\centering
908914
\\input{figure.pgf}
909-
\\end{document}""" % (w, h, latex_preamble, latex_fontspec)
915+
\\end{document}""" % (hyperref_options, w, h, latex_preamble, latex_fontspec)
910916
pathlib.Path(fname_tex).write_text(latexcode, encoding="utf-8")
911917

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

0 commit comments

Comments
 (0)