|
Rank: Member Groups: Member
Joined: 12/30/2012 Posts: 11
|
I am experiencing strange LastPosition values after converting a page that contains a css zoom/scale. This simple html reproduces the issue: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <body style="margin: 0; padding: 0;"> <div style="transform: scale(0.5); transform-origin:top left"> <div style="height: 790px; border:1px solid red">test</div> </div> </body> </head> </html>
var htmlToPdfOptions = new HtmlToPdfOptions(); htmlToPdfOptions.PageSize = new SizeF(PdfPageSizes.A4.Height, PdfPageSizes.A4.Width); htmlToPdfOptions.OutputArea = new RectangleF(0, 0, PdfPageSizes.A4.Height, PdfPageSizes.A4.Width); var htmlToPdfResult = HtmlToPdf.ConvertUrl(txtURL.Text, Server.MapPath(filePath), htmlToPdfOptions);
LabelDebug.Text += "[DEBUG: StartPosition: " + htmlToPdfResult.StartPosition + " LastPosition: " + htmlToPdfResult.LastPosition + "\n";
The page is rendered correctly but LastPosition is 8.260417. I get the same value if I do not set the scale factor. If I set a bigger height (for example <div style="height: 1790px; border:1px solid red">test</div>) I get 10.40625 (a value bigger than the page size). I get a similar strange behaviour in a portrait page. It is important for me to get the correct LastPosition because I need to add extra content in the same page and I need to know the exact free space available below the content. I’m using EO.Pdf 18.0.70 Thanks for your help.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,258
|
Hi, This is normal. Scale only affects rendering, it does not affect layout. LastPosition is based on layout, not rendering. So it won't be affected by scale. To demonstrate the difference between these two, you can add additional contents below your DIV in your original HTML. For example,
Code: HTML/ASPX
<div style="transform: scale(0.5); transform-origin:top left">
<div style="height: 790px; border:1px solid red">test</div>
</div>
<div style="background-color:red;width:100px;height:100px;">
</div>
If you load this HTML with the regular Google Chrome browser, you will see the red square (the second DIV) does not immediately follow the first DIV. Instead it appears much lower as if there was no transform on the first DIV at all. In another word, the scale settings on the first DIV does not affect the layout of the second DIV. If you want to scale the whole output, you can set HtmlToPdf.Options.ZoomLevel. That option does affect LastPosition. Thanks!
|
|
Rank: Member Groups: Member
Joined: 12/30/2012 Posts: 11
|
Hi, thanks for your explanation. I tried a different approach using css zoom() instead of transform: scale(). It seems to work correctly, but not in the particular case of an absolute element inside the scaled element. For example: <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body style="margin: 0; padding: 0;"> <div style="zoom:0.5"> <div style="position: relative; height: 790px; border:1px solid red"> <div style="position: absolute; left: 0px; top: 700px; background-color: yellow">test absolute</div> </div> </div> </body> </html>
The pdf is rendered correctly (the scale/zoom is applied as expected), but the LastPosition seems not to consider the zoom of the absolute element. If I remove the absolute element, LastPosition is correct and changes if I change the zoom level. Maybe it is related to the same layout/render issue of my previous example, but I cannot understand how to get the exact LastPosition in this situation. I cannot use ZoomLevel because I need to apply different scale factor to different elements in the same page. Thanks again!
|
|
Rank: Member Groups: Member
Joined: 12/30/2012 Posts: 11
|
Hi, I have tested this issue with the latest Eo.Pdf release (18.1.31) and I get the same result I described in my previous post: LastPosition seems not to consider the scale factor of the absolute element. Can you help me to understand this behavior? Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,258
|
Hi,
Sorry about the delay. This will be fixed in our next build. We will reply here again as soon as the new build is posted.
Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,258
|
Hi,
This is just to let you know that we have posted a new build that should fix this problem. You can download the new build from our download page. Please take a look and let us know how it goes.
Thanks!
|
|