JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<div align="center" >
<h4 align="center">
<u>Paste text in the field below to divide text into paragraphs.</u>
</h4>
<textarea placeholder="Type text here, then press the button below."
cols="50"
id="textarea1"
rows="10"></textarea>
<br>
<br>
<button id="Go">Divide Text into Paragraphs!</button>
<br>
<br>
<button id="DynamicParagrapsToJSPDF">Save as PDF</button>
</div>
<h2 align="center">
Dynamic Paragraphs will appear below:
<br>
[Paragraphs below for saving as PDF]
</h2>
<hr>
<div>
<div id="text_land"
align="center"
style="max-width: 210mm; min-width: 210mm; font-family: monospace; background-color: white; position: relative;">
</div>
</div>
CSS
@media print{
p{page-break-inside:avoid;},
.no-print,
.no-print *{display:none !important}
}
p{
position : relative ;
display : block ;
margin-bottom : 32mm ;
border-style : solid ;
color : #000000 ;
text-align : justify ;
border-width : 5px ;
font-size : 19px ;
overflow : hidden ;
height : 58mm ;
width : 100mm ;
word-wrap : break-word ;
}
JavaScript
$(function(){
$("#DynamicParagrapsToJSPDF").on("click",function(){
var pdf = new jsPDF('p', 'mm', [297,210]);
var options = {
pagesplit: true
};
pdf.addHTML($("#text_land"),options,function() {
pdf.save('web.pdf');
});
})
$("#Go").on("click",function(){
$('#text_land').html('');
var inputText=$("textarea").val();
var paragraphTexts = [ ];
var index=300;
for(; inputText.length>0; ){
for( ; inputText.length > index && " " !== inputText.charAt(index); )
{ index++; }
paragraphTexts.push(inputText.substring(0,index));
inputText=inputText.substring(index);
index=300;
}
for(var i=0; i<paragraphTexts.length; i+=2){
var page_html = '<div style="border: 1px solid white; padding-top: 32mm; display: block; max-width: 210mm; min-width: 210mm; min-height: 189.873mm; max-height: 189.873mm; position: relative;">';
page_html += "<p>"+paragraphTexts[i]+"</p>";
if((i+1)<paragraphTexts.length){
page_html += "<p>"+paragraphTexts[i+1]+"</p>";
}
page_html += '</div>';
$("#text_land").append(page_html);
$("p").attr("contenteditable","true");
$("p").addClass("text");
}
}
)
}
) ,
$("select").on("change",function(){
var t=$("#text_land p");
var e=this.dataset.property;
t.css(e,this.value)
}
).prop("selectedIndex",0), end;