是否可以使用JSPDF将包含边框的段落<p>
保存为PDF,将格式合并并保持元素位于页面中心?
以下代码允许在将文本粘贴到textarea
中时生成段落。正如在此Fiddle中展示的那样,似乎可以将表格保存为PDF。
然而,是否可能将以下动态段落和边框作为PDF动态保存?
如果可以提供更新的JSFiddle链接,将不胜感激,因为我还是编程新手。 JSFiddle 谢谢!
HTML:
<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>
</div>
<hr> <h2 align="center">Dynamic Paragraphs will appear below: <br>[Paragraphs below for saving as PDF]</h2> <div> <div align="center" id="text_land" style="font-family: monospace"> </div></div>
JQuery:
$(function(){$("#Go").on("click",function(){for(var t=$("textarea").val(),e=300;t.length;){for(;t.length>e&&" "!==t.charAt(e);)e++;$("#text_land").append("<br></br><p>"+t.substring(0,e)+"</p><br></br>"),t=t.substring(e),e=300,$("p").attr("contenteditable","true"),$("p").addClass("text")}})}),$("select").on("change",function(){var t=$("#text_land p"),e=this.dataset.property;t.css(e,this.value)}).prop("selectedIndex",0),end;
CSS:
@media print{p{page-break-inside:avoid}}p{position:relative}@media print{.no-print,.no-print *{display:none !important}}p{border-style:solid}p{color:#000}p{display:block;text-align:justify;border-width:5px;font-size:19px}p{overflow:hidden;height:300px;width:460px;word-wrap:break-word}
pagesplit: true
更改为pagesplit: false
,以便不进行分页,并且由于您在p
上有固定宽度,因此窗口的宽度无关紧要。如果您希望p
跟随窗口变化,请将p
的规则更改为百分比,例如width:80%;min-width:460px;
。 - Asons