2

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!

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
physiker
  • 889
  • 3
  • 16
  • 30
  • 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
  • 1
    Does this answer your question? [Merge PDF files](https://stackoverflow.com/questions/3444645/merge-pdf-files) – Charlie Mar 07 '23 at 21:03

2 Answers2

4

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

    pdfjam --nup 2x1 leftFig.pdf rightFig.pdf --outfile combinedFig.pdf
rmccloskey
  • 482
  • 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() 

https://web.archive.org/web/20150111073718/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?.

Lost Fool
  • 19
  • 5
Charlie
  • 2,004
  • 6
  • 20
  • 40