cfdocument防止中间分页 [英] cfdocument prevent page breaks mid-row

查看:140
本文介绍了cfdocument防止中间分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这已被问过,但解决方案是从2.5+年前,所以我问,如果有人设计或知道一个更优雅的解决方案使用CF9的问题。任何人都可以确认CF10是否支持page-break-inside:avoid规则?

I know this has been asked before but the solutions are from 2.5+ years ago so I'm asking if anyone has devised or knows of a more elegant solution to the problem using CF9. Can anyone confirm if CF10 supports the "page-break-inside: avoid" rule?

如何防止CFDocument中的分页中断发生在内容中?

COLDFUSION:cfdocument并强制分页

这是我怎么做。我估计,取决于什么类型的页面,我可以适合9或11行数据,在强制分页之前。当然这很容易崩溃,所以如果任何人知道解决方案的任何演变我会感激。

This is pretty much how I'm doing it. I've estimated, depending on what type of page it is, I can fit 9 or 11 rows of data before having to force a page break. Of course this is prone to breaking so if anyone knows of any evolution of the solution I would be grateful.

推荐答案

找到了一个伪解。它基本上就是我在上面的评论中说的。我采取最好的猜测,看看它是否适合使用cfpdf的getInfo.totalPages的值。如果适合,很好,将它合并到最终文档,如果没有,请再尝试一行。

I believe I have found a pseudo solution. It is basically just what I said in the comments above. I take a best guess and see if it fits using the value of cfpdf's getInfo.totalPages. If it fits, great, merge it to the final document, if it doesn't, try again with one less row.

这样做的缺点是它减慢了一点,你不能使用一些东西cfdocument使得容易像喜欢混淆标题和页脚。话虽如此,这个解决方案的第2部分可能是记录数组中适合页面的行数,而不是合并页面,并使用cfdocument重新构建整个文档,这些值作为循环约束强制分页后。因为它是,以下的解决方案已经是一点时间,所以再次建立一个cfdocument标记可能无法在高流量网站工作。

The downside to doing it this way is that it slows it down a bit and you can't use some of the stuff cfdocument makes easy like like messing with headers and footers. That being said, part 2 of this solution may be to record the number of rows that fit on a page in an array instead of merging the pages and rebuild the entire document again using cfdocument and those values as the loop constraints forcing a page break after. As it is, the below solution is already a little time consuming so building it again inside of a cfdocument tag may not work in high traffic sites.

Bug解决方法:似乎有一个与cfdocument的错误,当使用name属性将文档保存到内存时会删除背景颜色。解决方法是将cfdocument标记删除到外部文件。我看到一个程序员把它放入一个cfc,我发现可以使用一个简单的cfinclude。

Bug workaround: It looks like there is a bug with cfdocument that removes the background colors when saving the document to memory with the name attribute. The workaround is to remove the cfdocument tag to an external file. I saw one programmer placed it into a cfc, I found it's possible to use a simple cfinclude.

我希望有人发现这有帮助,如果你知道一个更好的方法

I hope someone finds this helpful, and if you know a better way to do this please comment.

<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)#">

这篇关于cfdocument防止中间分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆