Rank: Newbie Groups: Member
Joined: 1/25/2017 Posts: 2
|
I'm upgrading from an older version (5.0.63.2) where we have used HtmlToPdf.ConvertHtml on a page by page basis to ensure that only oversize pages are shrunk using AutoFitX=ShrinkToPage (and AutoFitY=None). Pages that fit within the boundaries are thus left at their original zoom level. As we export our customers custom reports that may take all shapes and forms, this is an important option.
With versions 16.2.93.0 and 17.0.40.0 I realized that some pages are shrunk without being oversize. It happens to some pages, but not all as if converting the entire document at once using AutoFitX=ShrinkToPage. If I rearrange the order of page,s some pages that were previously shrunk are now at their normal zoom level while others become smaller. Setting ZoomLevel didn't seem to have any effect, neither did creating a new document for every page and merging them afterwards.
It seems like the shrinking only carries over from one page to the next and not to further pages, so I started creating an almost blank page between all the other pages. Now all the real pages come out as expected, oversize pages shrunk and all others at their normal zoom. As I can merge all the real pages into a new PdfDocument and throw away all the others I get the document I want, but it is truly a hack and increases the conversion time. Is there a better way of "resetting" the zoom level?
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, We tested this here and it seems to work fine. Our test code is as follow:
Code: C#
//Convert the first file that is larger than the default size
//which results in shrinking the page contents
HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.ShrinkToFit;
HtmlToPdfResult result1 = HtmlToPdf.ConvertUrl("test1.html", "1.pdf");
//Convert the second file that is smaller than the default
//size so no shrinking should occur
HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.ShrinkToFit;
HtmlToPdfResult result2 = HtmlToPdf.ConvertUrl("test2.html", "2.pdf");
The content of test1.html is:
Code: HTML/ASPX
<head>
</head>
<body>
<div style="background-color:red;width:2000px;height:1000px;"></div>
</body>
</html>
The content of test2.html is:
Code: HTML/ASPX
<head>
</head>
<body>
<div style="background-color:red;width:500px;height:500px;"></div>
</body>
</html>
After the above code result1.ZoomLevel is 0.312 and result2.ZoomLevel is 1, which are correct. Can you try the same and see if you get the same result? Thanks!
|
Rank: Newbie Groups: Member
Joined: 1/25/2017 Posts: 2
|
I stripped off all javascript and unnecessary css from my html and the problem disappeared. Turned out that it was related to the way a 3rd party script library was loaded.
Thanks.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Great. Glad that you found out the root cause!
|