5

私はこれが以前に尋ねられたことを知っていますが、解決策は2.5年以上前のものなので、CF9を使用した問題のより洗練された解決策を誰かが考案または知っているかどうかを尋ねています。CF10が「page-break-inside:avoid」ルールをサポートしているかどうかを誰かが確認できますか?

CFDocumentのページ分割がコンテンツの途中で発生するのを防ぐにはどうすればよいですか?

COLDFUSION:cfdocumentと強制的なページブレーク

これは私がやっている方法とほとんど同じです。ページの種類に応じて、ページ分割を強制する前に9行または11行のデータを収めることができると見積もっています。もちろん、これは壊れやすいので、誰かがソリューションの進化を知っているなら、私は感謝するでしょう。

4

2 に答える 2

2

私は疑似的な解決策を見つけたと思います。それは基本的に私が上記のコメントで言ったことです。私は最善の推測をして、cfpdfのgetInfo.totalPagesの値を使用してそれが適合するかどうかを確認します。収まる場合は、それを最終的なドキュメントにマージします。収まらない場合は、1行少なくして再試行します。

この方法の欠点は、速度が少し遅くなり、ヘッダーやフッターをいじるような簡単なcfdocumentの一部を使用できないことです。そうは言っても、このソリューションのパート2は、ページをマージする代わりに、ページに収まる行数を配列に記録し、cfdocumentとそれらの値をループ制約として使用して、ドキュメント全体を再構築することです。 。現状では、以下のソリューションはすでに少し時間がかかるため、cfdocumentタグ内に再度ビルドすると、トラフィックの多いサイトでは機能しない可能性があります。

バグの回避策: name属性を使用してドキュメントをメモリに保存するときに、背景色を削除するcfdocumentにバグがあるようです。回避策は、cfdocumentタグを外部ファイルに削除することです。あるプログラマーがそれをcfcに配置しているのを見ましたが、単純なcfincludeを使用できることがわかりました。

誰かがこれがお役に立てば幸いです。これを行うためのより良い方法を知っている場合は、コメントしてください。

<cfset reviewText = "Lorem ipsum dolor sit amet, + lots of characters.">
<cfset estimatedRowsPerPage = 7> <!--- This is the max number of records you want to try on each page.  The larger the gap between max and actual will slow down the process. Used to reset attemptedRowsPerPage if the value changes --->
<cfset attemptedRowsPerPage = estimatedRowsPerPage> <!---- number of rows attempted to add to the page --->
<cfset totalRowsOutput = 0><!--- this is the number of records successfully saved to the final PDF --->
<cfset recordCount = 20> <!--- this is the query's record count --->
<!--- cfpdf cannot create a file from scratch and cfdocument requires some content so a container object cannot be created without at least one page. This page will be deleted later --->
<cfdocument format="pdf" marginbottom=".25" margintop=".25" marginleft=".25" marginright=".25" name = "finalDocument">Delete me</cfdocument>
<cfloop condition="totalRowsOutput lt recordCount">
    <!--- create what *should* be a single page document --->
    <cfdocument format="pdf" marginbottom=".25" margintop=".25" marginleft=".25" marginright=".25" name = "testDocument">
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title>A title</title>
            </head>
            <body>
                <table border="1">
                    <tr>
                        <td>Row:</td>
                        <td>Title:</td>
                        <td>Author:</td>
                        <td>Price:</td>
                        <td>Average Rating:</td>
                        <td>Reviews:</td>
                    </tr>
                    <cfoutput>
                    <cfloop from = "1" to = "#attemptedRowsPerPage#" index = "i">
                        <tr>
                            <td>
                                #i#
                            </td>
                            <td nowrap="nowrap">
                                #mid(reviewText,1,randRange(4,10))#
                            </td>
                            <td nowrap="nowrap">
                                #mid(reviewText,20,randRange(8,20))#
                            </td>
                            <td>
                                $10.00
                            </td>
                            <td>
                                #randRange(1,5)#
                            </td>
                            <td>
                                #mid(reviewText,1,randRange(10,700))#
                            </td>
                        </tr>
                    </cfloop>
                    </cfoutput>
                </table>
            </body>
        </html>
    </cfdocument>
    <!--- get the document info to see if the page count = 1 --->
    <cfpdf action="getinfo" source="testDocument" name="testInfo">
    <cfif testInfo.totalPages gt 1>
        <!--- if the page count is greater than 1 we need to try again with one less record. --->
        <cfset attemptedRowsPerPage -= 1>
    <cfelse>
        <!--- merge the new single page to the final document --->
        <cfpdf action = "merge" name = "finalDocument">
            <cfpdfparam source="finalDocument">
            <cfpdfparam source="testDocument">
        </cfpdf>
        <cfset totalRowsOutput += attemptedRowsPerPage>
        <!--- if the page count = 1, we need to increment the startAttempt and reset the attemptedRowsPerPage unless attemptedRowsPerPage = recordCount --->
        <cfif totalRowsOutput lt recordCount>
            <!--- don't try to output more than exist --->
            <cfset attemptedRowsPerPage = estimatedRowsPerPage+totalRowsOutput lt recordCount ? estimatedRowsPerPage : recordCount-totalRowsOutput>
        </cfif>
    </cfif>
</cfloop>
<!--- delete the manditory page needed to create our final document --->
<cfpdf action="deletePages" pages="1" source="finalDocument" name="finalDocument">
<!--- see "http://www.raymondcamden.com/index.cfm/2007/7/12/ColdFusion-8-Working-with-PDFs--A-Problem" to see why you need toBinary --->
<cfcontent type="application/pdf" variable="#toBinary(finalDocument)#">
于 2012-08-23T14:42:53.037 に答える
0

トラビス-私はこれを行う別の方法を知りません。通常、私は各「ページ」のコアとしてHTMLテーブルを作成し、テーブルを閉じてページを分割し、新しいテーブルを開く前に特定の行数を設定します。

于 2012-08-22T13:14:36.477 に答える