Created
May 1, 2015 21:16
-
-
Save williamgilpin/014caa2f613c94633a49 to your computer and use it in GitHub Desktop.
Add parameter values to a figure pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PyPDF2 as pdf | |
def fig_annotate(filename, params): | |
''' | |
Given a figure and a dictionary of values (like simulation parameter values) | |
associated with that figure, write in the "Keyword" metadata of the PDF the parameter list. | |
When conducting numerical simulations involving large numbers of parameters, it | |
can be difficult and confusing to keep track of which parameters are associated with which | |
figures. This function provides an additional check by allowing paramter values to be written directly | |
into the PDF file | |
William Gilpin, 2015 | |
''' | |
inpdf = pdf.PdfFileReader(filename) | |
mypage = inpdf.getPage(0) | |
outpdf = pdf.PdfFileWriter() | |
outpdf.addPage(mypage) | |
metadata_string = '' | |
for item in params: | |
metadata_string += str(item) + '='+str(params[item]) | |
metadata_string += ' ' | |
outpdf.addMetadata({'/Keywords': metadata_string}) | |
outputStream = open('intest.pdf', 'wb') | |
outpdf.write(outputStream) | |
outputStream.close() | |
# pvals = {'b':78, 'mg':0.03e-7} | |
# fig_annotate('intest.pdf', pvals) | |
def fig_get_annotations(): | |
''' | |
Given a figure with annotations written into the "keyword" field | |
using the format of fig_annotate.py, read those parameter values | |
and return a parameter dictionary | |
NOT YET IMPLEMENTED | |
''' | |
return None | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment