是否可以使用JSPDF保存包含邊框爲PDF的段落<p>
,合併格式並將元素保留在頁面中央?將段落保存爲PDF動態?
以下代碼允許在將文本粘貼到textarea
時生成段落。正如在Fiddle中所演示的,似乎可以將表格保存爲PDF。
但是,是否可以將以下動態段落和邊界動態保存爲PDF?
如果可以提供更新的小提琴,那將非常感謝,因爲我仍然是編碼新手。
謝謝!
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}
然而,調整窗口大小或縮放時,實際的段落元素不是保存爲PDF時指定的大小改變大小。此外,PDF文檔將該段落分割爲兩個單獨的頁面,而不是允許該段落通過頁邊距移動到下一頁。因此,是否有可能解決這些問題? – Dave
@Dave將'pagesplit:true'更改爲'pagesplit:false',因爲沒有分頁符,並且您的'p'的寬度固定不變,窗口的寬度無關緊要。如果你想'p'來跟隨窗口,把'p'的規則改成像'width:80%; min-width:460px;' – LGSon
這樣的百分比。另外,當保存爲PDF時,文本看起來很模糊。這是一個可以解決的問題,因爲它似乎是來自html2canvas的問題。 – Dave