So now let's go ahead and let's learn how we could write the data or print the data to the file which
we have in the chapter body.
So every chapter body which we create, it kind of has some data.
And that data needs to be printed up over to the page.
Now, even before printing up the data to the page, we first have to create that page as well and we
want to create a new page for every chapter which we have.
So the question is how to do that.
So we have two methods here.
One is print chapter and the next one is Chapter body.
So whenever we call print chapter, that actually creates a chapter body.
But even before creating a chapter body, we have to add a page as well.
So in order to add a page here, I would simply say self dot, that's going to be add underscore page
and this is going to add the page for us.
So once the page has been added, I could finally call this chapter body method and that's going to
add some contents to the page.
So we have already read the content which we need to add.
So instead of printing this up, I could delete this and instead of doing this, what I could do is
I could print up that particular thing in a cell.
Now, even before printing anything, we all know that we have to set the font.
So here I would say self dot, set, underscore font and I'll set the font to, let's say times new
Roman.
So I'll set it two times.
And if you don't have that font installed, what Fpdf does is that it will automatically set the by
default font which you have installed.
So let's set the size of a chapter text to 12.
All right.
So once we have this, now, the next thing which we need to do is we need to create a cell in order
to print up this particular text.
However, what we want to do here is that we want to split the text into multiple cells instead of creating
a single cell.
So in order to do that, or in order to kind of print up the cell into a paragraph kind of format,
I would use a method called as multi cell, which stands for multiple cell.
So I could say self dot multi cell.
And over here, the first parameter which you need to pass in is the width.
So you want the width of every cell to span the entire width.
So I'll pass in zero over here and the next thing is you need to pass in the height.
So let's say I want to pass in the height as five, and after that you actually need to pass in the
text which you want to print.
So over here I could say comma txt, which is nothing but the text which is being read from the file.
Now after creating this particular cell, I want to perform a line break because after creating a chapter
body you also need to have a line break as well.
So I could say self dot line, which is used for creating the line break.
Now after this, what I could do is I could display a message which would say something like, okay,
this is the end of the script.
So here I would set the font and make it kind of italic.
So here I could say self dot set font and set this thing to.
Stylus italic and that's it.
After this, I would simply add a cell which says something like.
Zero as the width.
Five as the height.
And the text is going to be something like.
And of X script.
Okay, so once this thing is done, we are pretty much good to go.
So we are creating the chapter.
We are kind of adding the chapter body.
We are adding the text to that chapter body by creating some cells.
But now you also need to generate a PDF file over here as well.
So what we will be doing here is that once you call this particular print chapter, this only prints
one chapter.
But what if you have two chapters and you want to print them over here?
So you could do that and after printing multiple chapters is when you would finally output the PDF file.
So this line of code over here simply creates one chapter.
So I would say this creates one chapter, and you could create a second chapter by reading text from
some other file.
And after creating that chapter, you could finally go ahead and print up the output.
So here I would say pdf dot output and simply output the sample dot pdf file.
So let's see if this works.
So I'll save the code.
I'll go back to the terminal, run the code.
And now the sample pdf file has been created.
And as you can see, this is what it currently looks like.
So as you can see, it took all the content which we had up over there and right now we have multiple
pages here and now here we have end of X script.
That means here is where the chapter ends.
Now the question is how exactly we will be able to know that the chapter starts here and it ends here
and how to add or create another chapter.
So for that we actually need to set the chapter title, the header and the footer so that the chapters
could be separated from one another.
So in the next lecture, let's go ahead and let's learn how you could add the chapter header, the chapter
footer, and also the chapter title as well.
So thank you very much for watching and I'll see you guys in the next one.
Thank you.