Monday, March 26, 2012

PDF export results in extra pages.

I am experiencing some quirks when exporting to PDF.
I have read all the other posts about page sizes, margins, etc and my situation seems to be a bit different.

PageWidth = 21cm
PageHeight = 29.7cm
Margins = 1cm

Body.Width = 19cm

I have a report that contains a bar chart (Height = 15cm, Width = 19cm) and below that a rectangle that contains two text boxes with totals information (Left = 11.6cm, Width = 7.4cm, Height 0.5cm)

Now most of the time it exports to PDF perfectly - all on one page as would be expected

If however the chart has more than say 20 items on the y-axis then the rectangle gets pushed onto an new page.

For extra information, but not to confuse the issue I also have a page header and footer that have items lined up right to the edge (left + width = 19cm) and they all display fine on the one page. It is just this rectangle that is having the problem.

When I move the rectangle to the left a bit (11.4cm) so 0.2cm away from the right hand edge then it works fine.

It is just very strange because I cant see how it is getting shifted only when the chart contains a lot of items.

Any ideas?

I finally found a solution that works for me, just after I posted - usually the way.

I have created a rectangle with left = 0cm and width = 19cm and then placed the text boxes
inside that rectangle, positioned where I need them.

Once I do that it renders onto one page.

What I think is going on here is a precision problem. I suspect that MS being a US based company their base units are the imperial system so Inches. So even though you can express your measurements in cm, pt's, etc - they are always converted to a base unit of inches. With any conversion process you can get problems with precision and that is what I think is happening here.

So I feel the best way to avoid these precision bugs is to adopt a report design strategy of not having floating report items in your report. Group items by placing them in a rectangle and set the left to 0 and the width to the exact page width boundary (in this case 19cm)

The other solution is to always use the same base units as the renderer (inches) that way you wont suffer conversion precision problems. Unfortunately for me it would take forever to convert all mine from cm to inches.

No comments:

Post a Comment