John Davidson

javascript - Divide the html page into several pages automatically like MS WORD

0 comments
Message:


Is ther any way to divide a html context contained div, p and table tages into separated pages in separated div tages (or at least just separated) for a defined height? (like ms word but online)


I want to create an html template for formal letters that might have multiple pages.
Expected a solution by using php or javascript or just html and css.


I use a persian font not english !


By the way, is there any other ways for creating those types of templates? (not using third party websites)... If yes, please give an example.


Note that I want to create pdf and image and ms word doc from that html too!


Thanks :)



My Answer:
One way to achieve this is by using CSS for page breaks. You can use the `page-break-before` or `page-break-after` properties to force a page break after a specific element.

Here is an example of how you can divide your HTML content into separate pages using CSS:

html





Page Break Example




Page 1 content goes here...




Page 2 content goes here...







You can adjust the height of each page by adding more content to each `div.page` element. When you convert this HTML to PDF or MS Word, the page breaks will be respected.

For converting HTML to PDF, you can use libraries like `mpdf` or `dompdf` in PHP. For converting HTML to images, you can use libraries like `html2canvas` in JavaScript.

I hope this helps! Let me know if you have any further questions.

Rate this post

4 of 5 based on 5867 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us