CFDocument Page Break

610 views
Skip to first unread message

Pritesh

unread,
Aug 22, 2010, 2:40:30 PM8/22/10
to Railo
Is there a way of stopping data spanning over two pages and forcing a
page break? I have tried page-break-inside: avoid but did not working
for me. Here is my code:

<cfdocument
format="PDF"
filename="#filename#"
overwrite="yes"
pagetype="A4"
orientation="portrait"
margintop="0.75"
marginbottom="1.5"
marginleft="0.5"
marginright="0.75"
unit="cm"
fontembed="yes"
mimetype="text/plain">

<style type="text/css">
div.category {color: White; font-family: Arial; font-weight: bold;
font: 9px; text-decoration: none; background-color: Black; width:100%;
margin-bottom:1px;}
div.row {width:100%; line-height: 9px;}
div.row1 {width:100%;}
div.insolvent {width:9cm; float:left; text-align:left; color:Black;
font-family:"Helvetica-Condensed-Thin"; font-weight:bold; font: 8px;
text-decoration:none;}
div.businessNature {width:5.91cm; float:left; text-align:left;
color:Black; font-family:"Helvetica-Condensed-Thin"; font-weight:none;
font: 8px; text-decoration:none; font-style: italic;}
div.type {width:1cm; float:left; text-align:right; color:Black; font-
family:"Helvetica-Condensed-Thin"; font-weight:none; font: 8px; text-
decoration:none;}
div.details {width:9cm; float:left; text-align:left; color:Black;
font-family:"Helvetica-Condensed-Thin"; font-weight:none; font: 8px;
text-decoration:none;}
div.tel {width:2.6cm; float:left; text-align:left; color:Black; font-
family:"Helvetica-Condensed-Thin"; font-weight:none; font: 8px; text-
decoration:none;}
div.web {width:4cm; float:left; text-align:left; color:Black; font-
family:"Helvetica-Condensed-Thin"; font-weight:none; font: 8px; text-
decoration:none;}
table {border-top:1px gray; margin-top:1px; margin-bottom:3px;
padding-top:0px; padding-bottom:0px; width:100%;}
</style>

<cfoutput query="MyQuery" group="businessCategory">
<div class="category">#businessCategory#</div>
<cfoutput>
<div STYLE="page-break-inside: avoid">
<div>
<div class="row">
<div class="insolvent">#insolvent#</div>
<div class="businessNature">#businessNature#</div>
<div class="type">#insolvencytype#</div>
</div>
<div class="row">
<div class="details">#practitioners_details#</div>
<div class="tel">#practitioners_tel#</div>
<div class="web">#practitioners_web#</div>
</div>
</div>
<table></table>
</div>
</cfoutput>
</cfoutput>
</cfdocument>

I would like everything in the second set out CFOUTPUT tags to remain
on one page.

Paul Klinkenberg

unread,
Aug 22, 2010, 3:59:31 PM8/22/10
to ra...@googlegroups.com
Hi Pritesh,

You should add a <body> tag, and set an explicit width for it in the css. Otherwise, the html parser needs to guess itself how wide/high the page is.
So something like  body { width: 20cm; height: 28cm; }  or body { width: 1000px; height: 1400px; } should be able to get you going.
Good luck!
 
Kind regards,

Paul Klinkenberg
www.railodeveloper.com



Pritesh

unread,
Aug 22, 2010, 5:40:08 PM8/22/10
to Railo
Hi Paul,

I tried adding the <body> tag and setting the explicit width and
heights in the css - this did not work. I also then tried to add in
the <html> and <head> tags but this did not help either.

Regards,

Pritesh

Andrew Penhorwood

unread,
Aug 22, 2010, 6:00:48 PM8/22/10
to Pritesh
Pritesh,

I tried using CFDocument but never got it to work like I wanted. Then
I found this post on the railo group.

http://www.andreacfm.com/post.cfm/replace-cfdocument-with-flying-source-xhtml-renderer

Which points to this project. https://xhtmlrenderer.dev.java.net/

I used Flying Saucer jars in my latest project at work. It works
great on Railo and CF8.

Andrew Penhorwood

> Hi Paul,

> Regards,

> Pritesh

--
Best regards,
Andrew Penhorwood
and...@coldbits.com
www.coldbits.com
336-501-0958 cell

Paul Klinkenberg

unread,
Aug 22, 2010, 6:12:37 PM8/22/10
to ra...@googlegroups.com
Hi Pritesh,

If it will fit on one page, depends on how much data you've got.

You can find out a pdf page's height, if you know how wide a page will be. Setting the height of the body as I suggested isn't actually a good thing, sorry for that.
If the body is 1000px wide, then the height will be (height/width * 1000px). For A4, that will be 29.7/21 * 1000 = 1414px.
But you also have to take the pdf margins into the calculation.

You could start each business category on a new page, by setting a <cfdocumentitem type = "pagebreak"/> after each iteration.

Or calculate before the iterations if it will still fit on the current page, and if it doesn't, then add the <cfdocumentitem type = "pagebreak"/>.
But then you need to know the exact height of each row, so you should either set "overflow:hidden" to the <div class="row">, or increase the "rowheight" in the following example to acommodate any possible higher rows.
And remove the "<table></table>" as well; it doesn't do anything good for your code.

You can do it something like this:

<cfset allowedPageHeight = 1414 />
<cfset currentpageheight = 0 />
<cfset headerHeight = 30 />
<cfset rowheight = 20 />

<cfoutput query="MyQuery" group="businessCategory">
<cfset heightToCome = headerHeight />
<cfoutput><cfset heightToCome += rowheight /></cfoutput>
<cfif currentpageheight + heightToCome gt allowedPageHeight>
<cfdocumentitem type = "pagebreak"/>
<cfset currentpageheight = heightToCome />
<cfelse>
<cfset currentpageheight += heightToCome />
</cfif>
        <div class="category">#businessCategory#</div>
                <cfoutput>
                <div STYLE="page-break-inside: avoid">
                <div>
                        <div class="row">
                                <div class="insolvent">#insolvent#</div>
                                <div class="businessNature">#businessNature#</div>
                                <div class="type">#insolvencytype#</div>
                        </div>
                        <div class="row">
                                <div class="details">#practitioners_details#</div>
                                <div class="tel">#practitioners_tel#</div>
                                <div class="web">#practitioners_web#</div>
                        </div>
                </div>
                <table></table>
                </div>
                </cfoutput>
        </cfoutput>

Kind regards,

Paul Klinkenberg
www.railodeveloper.com




Reply all
Reply to author
Forward
0 new messages