I have a custom UIPrintPageRender that utilises html to generate a pdf report.

What I'm finding is that the final rendered html doesn't consume the calculated height I pass as the pageRender's contentHeight leaving a blank space between the header and body content.

During my tests what I've found is that this blank space increases as the html content grows.

The height of the rect passed to drawHeaderForPageAtIndex:inRect: is correct. I even use this to draw the bottom of the header (even though I've got a typo and it says footer in the screenshots).

I also use javascript to calculate the html content height and it shows the expected height also which can be compared to the page ruler on the left hand side.

You can see that in the image below the rendered html doesn't consume the full height of the header leaving extra spacing.

enter image description here

I've attached the original image here! (not the thumbnail) to illustrate the problem better.

Has anyone come across this problem before or know what I'm doing wrong when drawing the header?

UPDATE:
I've now simplified my test to exclude the header/footer drawing just the body and I'm seeing the same result.

It appears both the UIWebViewPrintFormatter and UIMarkupTextPrintFormatter will shrink the content vertically by 20%. In the output below you can see a doc height of 220px but the formatter output is ~176px.

If I draw an image using the UIViewPrintFormatter into the body the height is correct so there is nothing weird going on with the page renderer itself.

webViewDidFinishLoad: document height: 220.00
pdf page size: {595.44006, 841.67999}
SATestPageRendererInit pageRect: {{0, 0}, {595.44006, 841.67999}}, pageMargin: {0, 0, 0, 0}
printableRect: {{0, 0}, {595.44006, 841.67999}}
pdfContextAddPage: 0 - pageRect: {{0, 0}, {595.44006, 841.67999}}
drawPageAtIndex: 0 inRect: {{0, 0}, {595.44006, 841.67999}}
drawPrintFormatter: forPageIndex: 0 printFormatterRect: {{0, 0}, {595.44006, 176.07098}}

0

There are 0 best solutions below