public void GeneratePages(string doc) { Bitmap htmlImage = RenderHtmlToBitmap(doc); int pageWidth = 800; int pageHeight = 600; int xLoc = 0; int yLoc = 0; int pages = 0; do { int remainingHeightOrPageHeight = Math.Min(htmlImage.Height - yLoc, pageHeight); int remainingWidthOrPageWidth = Math.Min(htmlImage.Width - xLoc, pageWidth); Rectangle cropFrame = new Rectangle(xLoc, yLoc, remainingWidthOrPageWidth, remainingHeightOrPageHeight); Bitmap page = htmlImage.Clone(cropFrame, htmlImage.PixelFormat); pages++; PageImageEventArgs args = new PageImageEventArgs { PageImage = page, PageNumber = pages }; OnPageReady(args); yLoc += pageHeight; if (yLoc > htmlImage.Height) { xLoc += pageWidth; if (xLoc < htmlImage.Width) { yLoc = 0; } } }while (yLoc < htmlImage.Height && xLoc < htmlImage.Width); }
protected virtual void OnPageReady(PageImageEventArgs e) { EventHandler <PageImageEventArgs> handler = this.PageReady; if (handler != null) { handler(this, e); } }
public void GeneratePages(string url) { Bitmap htmlImage = RenderHtmlToBitmap(url); int pageWidth = 800; int pageHeight = 600; int xLoc = 0; int yLoc = 0; int pages = 0; do { int remainingHeightOrPageHeight = Math.Min(htmlImage.Height - yLoc, pageHeight); int remainingWidthOrPageWidth = Math.Min(htmlImage.Width - xLoc, pageWidth); Rectangle cropFrame = new Rectangle(xLoc, yLoc, remainingWidthOrPageWidth, remainingHeightOrPageHeight); Bitmap page = htmlImage.Clone(cropFrame, htmlImage.PixelFormat); pages++; PageImageEventArgs args = new PageImageEventArgs { PageImage = page, PageNumber = pages }; OnPageReady(args); yLoc += pageHeight; if (yLoc > htmlImage.Height) { xLoc += pageWidth; if (xLoc < htmlImage.Width) { yLoc = 0; } } } while (yLoc < htmlImage.Height && xLoc < htmlImage.Width); }
protected virtual void OnPageReady(PageImageEventArgs e) { EventHandler<PageImageEventArgs> handler = this.PageReady; if (handler != null) handler(this, e); }