1

I have 2 different pdf plots (generated by matplotlib also) and I'd like to combine them as one side-by-side. Originally I wanted to generate with 2 subplots 121 and 122 but then was too tricky to adjust many details. So I generated two independent plots.

Is there any way to import those ready pdfs and just make one out of them? Because at the end in a latex file which I am using, it is much easier to deal with one figure file rather than two!

Thank you!

tacaswell
  • 79,602
  • 19
  • 200
  • 189
physiker
  • 809
  • 2
  • 15
  • 27
  • 1
    I actually think this is something that's easier to do in LaTeX using [subfigures](http://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions#Subfloats). – Roger Fan Aug 22 '14 at 16:16
  • I agree with @RogerFan. It is usually much better to use `subfigure` in latex, so that you also have two separate subcaptions. – gg349 Aug 22 '14 at 18:29
  • I agree that many times it is easier and I have used subfigure routinely also. For this particular case, I wanted to use just one figure. – physiker Aug 23 '14 at 11:41

2 Answers2

3

If you are on Linux or Mac, the pdfjam program can do it.

    pdfjam --nup 2x1 leftFig.pdf rightFig.pdf --outfile combinedFig.pdf
rmccloskey
  • 472
  • 5
  • 14
  • this is very handy! My favorite command line for dealing with pdf was/is pdftk but this seems to be more advanced. Thanks! – physiker Aug 23 '14 at 11:43
0

I would save the plots as PNGs and then create a PDF out the PNGs using ReportLab. For example:

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter

c = canvas.Canvas('report.pdf', pagesize=letter)    

c.drawImage('filename1.png', 0,0)
c.drawImage('filename2.png', 0,100)

c.save() 

http://www.reportlab.com/apis/reportlab/2.4/pdfgen.html

Or if you're set on merging multiple PDFs than that's already been answered here: Merge PDF files or you can merge image directly using PIL see here: How do you merge images into a canvas using PIL/Pillow?.

Community
  • 1
  • 1
Charlie
  • 1,692
  • 3
  • 17
  • 34