/// <summary> /// Currently used by the image server /// to get thumbnails that are used in the add page dialog. Since this dialog can show /// an enlarged version of the page, we generate these at a higher resolution than usual. /// Also, to make more realistic views of template pages we insert fake text wherever /// there is an empty edit block. /// /// The result is cached for possible future use so the caller should not dispose of it. /// </summary> /// <param name="book"></param> /// <param name="page"></param> /// <param name="isLandscape"></param> /// <param name="mustRegenerate"></param> /// <returns></returns> public Image GetThumbnailForPage(Book.Book book, IPage page, bool isLandscape, bool mustRegenerate = false) { 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, MustRegenerate = mustRegenerate }; 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)); }