Welcome back.
It's time for us to do something more useful.
And what I want to do is actually combine PDFs.
So I have this dummy PDF and then I also have this two page PDF and maybe we have a scenario where we
want to combine PDFs.
To form just one super pdf.
How can we do that?
Well, let's create a python program.
What I want to do is I want to be able to call Python three PDF and then give it some arguments.
Maybe to be able to say dummy dot pdf and then combining it with two page dot pdf.
And you know what?
Let's combine tilt to PDF as well and we can just keep adding and adding and adding different PDFs and
combining them.
Wouldn't that be cool?
Well, let's do that.
The first thing I'm going to do is import the CIS module so that we can get the arguments.
So I'm going to say inputs is going to equal cis dot arc v.
And I'm going to do a little trick here.
I'm going to say one and then Colon.
And remember, this is going to grab all the arguments besides the first one, which is our Python file,
but it's going to grab all of these into a list called inputs.
So we can include as many PDFs as we want from here.
Let's create a function just to have our code be clean.
So I'm going to remove this and call a function pdf.
Combiner.
And this pdf Combiner is going to take a PDF list, which is going to be our inputs and what should
we do here?
There are.
First thing I want to do is just make sure my code works.
So I'm going to do a forward loop and say PDF in PDF list.
And we're just going to print the PDF.
So again, just to test our code, let's see if this works.
I'm going to run this code.
Well and we have to call our function.
So let's say pdf combiner and just give it the inputs.
So I'm going to run this.
And there we go, our three PDFs.
That's great.
But we want to actually combine these.
So the way to do this is we actually have a merger object with PI PDF.
So this merger object, we can say pi.
PDF Dot pdf file merger.
So that gives us a merger object.
And the cool thing is that this is going to be really simple.
All we have to do here is within our loop, say merger dot.
Append.
PDF.
So this just tells us, hey, merge everything into this merger object, the PDFs that we're going to
loop through.
And at the end of the loop, this merger is going to have all these three PDFs.
And all we need to do is say merger.
Dot.
Right.
And just write the new PDF as well.
Let's call it super dot pdf.
So let's see if this works.
I'm going to run.
And did you see that?
We now have a super pdf.
If I open this.
All right, we have the dummy PDF and we see over here we have four pages, we have dummy PDF, we have
the simple PDF file that has two pages and we have our rotated dummy PDF file.
How cool is that?
And notice here that we didn't have to even do the width open as file and then actually write.
We can just use the merger dot right method to right our file so we have a pdf combiner.
If we're working on a book, for example, and maybe we have different people working on different chapters,
I can just run it through this function now and combine my entire PDF into one.
Very, very cool.
Or at least I think at school.
I hope you find this interesting as well.
But you know what?
Let's go even higher in the next video.
I want to do something that's actually, I think, quite useful.
So let's take a break and I'll see you in the next one.