0

I am using python to generate a set of plots. I then save these plots into a PDF document. Along the way I also produce a log file which details all the variables and other information in the program.

At the end of the day I have two files, one plots.pdf and one log.txt

What I really need to do is attach or append the log.txt file to the plots.pdf file.

How can I do this in python?

Ideally I would like to generate them each individually and then at the end attach/append the log.txt to the plots.pdf

I have seen answers showing how to add text to a pdf but not attach or append a file.

Like this: log.txt attached to PDF file

Thanks!

user1408329
  • 53
  • 1
  • 6
  • 4
    Possible duplicate of [Add text to Existing PDF using Python](http://stackoverflow.com/questions/1180115/add-text-to-existing-pdf-using-python) – dahrens Jan 18 '17 at 18:00
  • Not really, that example adds text to a PDF, I want to attached a .txt file to the PDF. – user1408329 Jan 18 '17 at 18:15
  • this is the same as your txt files includes plain text - you can easily read the text from the file or even don't write it there, if this is under your control and than use the approach mentioned above. – dahrens Jan 18 '17 at 18:18
  • Could you not just add the contents of the `log.txt` to the end of the the PDF using the instructions posted by dahrens? – nbryans Jan 18 '17 at 18:19
  • Possibly but my requirement is to attached the log.txt as a standalone file and not to just add text to the pdf. – user1408329 Jan 18 '17 at 18:48
  • One option to to use pdftk from the shell `pdftk in.pdf log.attach_files log.txt output out.pdf` – dwarring Jan 18 '17 at 19:50

0 Answers0