public Image GetThumbnailForPage(Book.Book book, IPage page, bool isLandscape)
{
var pageDom = book.GetThumbnailXmlDocumentForPage(page);
var thumbnailOptions = new HtmlThumbNailer.ThumbnailOptions()
{
BackgroundColor = Color.White,// matches the hand-made previews.
BorderStyle = HtmlThumbNailer.ThumbnailOptions.BorderStyles.None, // allows the HTML to add its preferred border in the larger preview
CenterImageUsingTransparentPadding = true
};
var pageDiv = pageDom.RawDom.SafeSelectNodes("descendant-or-self::div[contains(@class,'bloom-page')]").Cast<XmlElement>().FirstOrDefault();
// The actual page size is rather arbitrary, but we want the right ratio for A4.
// Using the actual A4 sizes in mm makes a big enough image to look good in the larger
// preview box on the right as well as giving exactly the ratio we want.
// We need to make the image the right shape to avoid some sort of shadow/box effects
// that I can't otherwise find a way to get rid of.
if (isLandscape)
{
thumbnailOptions.Width = 297;
thumbnailOptions.Height = 210;
pageDiv.SetAttribute("class", pageDiv.Attributes["class"].Value.Replace("Portrait", "Landscape"));
}
else
{
thumbnailOptions.Width = 210;
thumbnailOptions.Height = 297;
// On the offchance someone makes a template with by-default-landscape pages...
pageDiv.SetAttribute("class", pageDiv.Attributes["class"].Value.Replace("Landscape", "Portrait"));
}
// In different books (or even the same one) in the same session we may have portrait and landscape
// versions of the same template page. So we must use different IDs.
return _thumbnailProvider.GetThumbnail(page.Id + (isLandscape ? "L" : ""), pageDom, thumbnailOptions);
}