PDFMakeで残りのページの高さを動的にチェックする方法はありますか? 動的にページを作成するとき、残りの利用可能なページの高さをチェックして要素の高さと比較できるようにしたいので、ページの最後の要素 (画像や長いテキストエリアのコンテンツなど) を切り取ることはできず、別のページに転送できます。代わりは。動的に行う方法がわかりません。
6368 次
4 に答える
6
皆さんに感謝します。最後に、pageBreakBefore 関数と、マーカーとして使用する headlineLevel を使用し、ノードが画像かどうかを確認できる pdfmake のバージョンを見つけたので、要素の高さを計算しました。これが私のコードでどのように見えるかです。そこにはフッターもあり、計算でそれを考慮して、コンテンツが上に行かないようにする必要があります。
pageBreakBefore: function(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
var pageInnerHeight = currentNode.startPosition.pageInnerHeight;
var top = (currentNode.startPosition.top) ? currentNode.startPosition.top : 0;
var footerHeight = 30;
var nodeHeight = 0;
if (followingNodesOnPage && followingNodesOnPage.length) {
nodeHeight = followingNodesOnPage[0].startPosition.top - top;
}
if (currentNode.headlineLevel === 'footer') return false;
return (currentNode.image && (top + nodeHeight + footerHeight > pageInnerHeight))
|| (currentNode.headlineLevel === 'longField' && (top + nodeHeight + footerHeight > pageInnerHeight))
|| currentNode.startPosition.verticalRatio >= 0.95;
}
于 2017-01-04T10:21:17.893 に答える
0
手動でやっています。必要なのは、テキストが出始める前に、ページの最大サイズを知ることだけです。私の場合、テキストが切り捨てられる前のリーガル用紙サイズの最大幅は 700px です。
だから私がしていることは、totalPageWidthがacceptableWidthよりも小さくなるまで、ループ内の列幅を減らすことです. あまり読みにくいかもしれませんが、コードは次のとおりです。
// For a legal size page, total width is 700. So try and push all columns within 700
// Following lines are there to reduce the width of columns so as to adjust the total width.
// Width is deducted for every column so as not to affect any individual column.
totalOutOfPageWidth = totalWidth - 700;
var totalWidthDeducted = 0;
while (totalOutOfPageWidth > 0) {
for (var c = 0; c < colWidthArray.length; c++) {
if (totalOutOfPageWidth > 0) {
if (colWidthArray[c] == width70 - totalWidthDeducted) {
colWidthArray[c] = colWidthArray[c] - 5;
totalOutOfPageWidth -= 5;
}
}
}
if (totalOutOfPageWidth > 0) {
for (var c = 0; c < colWidthArray.length; c++) {
if (colWidthArray[c] == width50 - totalWidthDeducted) {
colWidthArray[c] = colWidthArray[c] - 5;
totalOutOfPageWidth -= 5;
}
}
}
if (totalOutOfPageWidth > 0) {
for (var c = 0; c < colWidthArray.length; c++) {
if (colWidthArray[c] == width35 - totalWidthDeducted) {
colWidthArray[c] = colWidthArray[c] - 5;
totalOutOfPageWidth -= 5;
}
}
}
if (totalOutOfPageWidth > 0) {
for (var c = 0; c < colWidthArray.length; c++) {
if (colWidthArray[c] == width25 - totalWidthDeducted) {
colWidthArray[c] = colWidthArray[c] - 5;
totalOutOfPageWidth -= 5;
}
}
}
totalWidthDeducted += 5;
于 2016-07-20T04:12:32.413 に答える