Hey, welcome to the last video of this app.
In the previous video we constructed this PDF file.
In this video we will go from this PDF to this PDF.
So we will add this last row here which contains the total price of all the products, and then we will
add these other two lines.
So we have this sentence which mentions the total price again.
And we also have this line where we have this company name and the logo of the company.
So you learn how to add images to PDF documents.
Let's do this.
So the first question is how do we calculate the total price and where do we work?
Do we work inside this full loop?
So should we write code inside the for loop in here?
Or should we write the code outside of the full loop?
For that you need to look at the PDF again to understand the problem here.
So we added multiple lines using the full loop, but now we only need to add one line with the total
price.
So the key word here is one.
It's not multiple.
Therefore, we need to be outside of the full loop.
And to give the total price, you can do something like this.
Let's go to the python console and make sure you have imported pandas and you have read the dataframe
in here.
And I have done that already.
So I have a dataframe in the D variable.
So you can see that I read the dataframe previously in here for that first Excel file.
So no, to get the column of product.
Let's see exactly what that column is.
So total price of each product is in the total price column.
So that gives us this column.
Now, to get the sum of that column, you do that again and then you add the sum method.
That gives you the sum of.
That's columns 302 plus 37.
We get three, three, nine and that is the number now, which we need to add as a new row in here outside
of the full loop.
So I'm going to copy these lines.
Place them outside of the four loop.
Again, I want to emphasize that.
And then so we have multiple cells here.
And what I'll do is I'll have empty strings in the first cells like that, like that.
And for this, I'm going to have the sum, let's say total sum, which is a variable we haven't calculated
yet in the script here.
We did that in the Python console, but that's another story.
So total sum is equal to that code.
Copy that, paste it in here.
So there goes total some.
But this should go as a string because text expects strings, not integers or floats.
Yeah.
Let's run this.
Check the first PDF.
And there we go.
So that is an empty string.
That is an empty string.
Empty string.
And that is the sum.
So that's what I did in here with these anti strings in here, Right?
That's how we add the total sum.
Now, let's add those two lines using cell set phones.
In here and let's copy the cell as well.
The text should be an F string.
So we want to write something like the total price as a placeholder.
And here goes the total sum variable, which we calculated in here.
And then another cell.
Or this shouldn't have a border, but it should have an ln of one.
And then I'll duplicate these lines.
So at total sum sentence then this would be at.
Company name and logo.
So that would be Python.
How?
And next to Python how we want the image, the logo.
So I'll remove the brick line because they have to be next to each other.
So next to this should be pdf dot image and image gets us input the path to the image file.
So you can find this image attached in the lecture resources.
So you should get that image.
Copy it and paste it in the root directory.
So just here you may want to add it to git.
So make sure this is green color.
As in my case, if it's red, you should click here, go to get and add it to the repository.
So make sure that name corresponds to that name.
Python.
How dot png python are the P and G and give it a width of ten should be good, otherwise the image might
be bigger or smaller.
So run this.
Open one of the files and yeah, there we go.
To make the image closer to Python.
Now, you can do some changes in here.
You can set the font of the company name to something bigger.
Make it 25 as the width of the company name.
Maybe change the style to bold for this.
And also for the sentence style is equal to bold.
And I'll run again.
Open the first PDF.
And that looks okay.
So you can tweak these fonts further if you like, but I'll just leave it here as it is.
I think we did a great job with this program.
So that's the final code.
Let's commit the changes.
So that's the files.
We changed the 26 and we added a header.
We added the total price as well.
Company and logo commit.
And thanks a lot for following.
This was quite a long program to write, but I hope that this cleared up your doubts about for loops
especially, and it should have given you more and more practical skills and a deeper understanding
of Python.
We still have a lot to go.
Lots of interesting programs.
So keep it up and I'll see you in the next videos.
See you.