Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerate image from url. Not working with aspx page?
    primarykey
    data
    text
    <p>I'm trying to produce a report using c#. First part of the report gets a visual image of a lot (using Mapguide) and places it in a PDF This part works fine.</p> <p>Next part requires converting a dynamic web page to an image to be inserted into the PDF. The problem is I have no control over how the webpage is created it seems to be produced as part of a webservice or an ASPX page (<a href="http://nautilus/maint_responsibility/rpt_summary.aspx?lease_code=TL01306" rel="nofollow noreferrer">http://nautilus/maint_responsibility/rpt_summary.aspx?lease_code=TL01306</a>)</p> <p>The application hangs while trying to produce an image from the above url :( This is the class im using</p> <pre><code>using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Threading; using System.Windows.Forms; public class WebsiteToImage { private Bitmap m_Bitmap; private string m_Url; private string m_FileName = string.Empty; public WebsiteToImage(string url) { // Without file m_Url = url; } public WebsiteToImage(string url, string fileName) { // With file m_Url = url; m_FileName = fileName; } public Bitmap Generate() { // Thread var m_thread = new Thread(_Generate); m_thread.SetApartmentState(ApartmentState.STA); m_thread.Start(); m_thread.Join(); return m_Bitmap; } private void _Generate() { var browser = new WebBrowser { ScrollBarsEnabled = false }; browser.Navigate(m_Url); browser.DocumentCompleted += WebBrowser_DocumentCompleted; while (browser.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } browser.Dispose(); } private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { // Capture var browser = (WebBrowser)sender; browser.ClientSize = new Size(browser.Document.Body.ScrollRectangle.Width, browser.Document.Body.ScrollRectangle.Bottom); browser.ScrollBarsEnabled = false; m_Bitmap = new Bitmap(browser.Document.Body.ScrollRectangle.Width, browser.Document.Body.ScrollRectangle.Bottom); browser.BringToFront(); browser.DrawToBitmap(m_Bitmap, browser.Bounds); // Save as file? if (m_FileName.Length &gt; 0) { // Save m_Bitmap.SaveJPG100(m_FileName); } } } public static class BitmapExtensions { public static void SaveJPG100(this Bitmap bmp, string filename) { var encoderParameters = new EncoderParameters(1); encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); bmp.Save(filename, GetEncoder(ImageFormat.Jpeg), encoderParameters); } public static void SaveJPG100(this Bitmap bmp, Stream stream) { var encoderParameters = new EncoderParameters(1); encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); bmp.Save(stream, GetEncoder(ImageFormat.Jpeg), encoderParameters); } public static ImageCodecInfo GetEncoder(ImageFormat format) { var codecs = ImageCodecInfo.GetImageDecoders(); foreach (var codec in codecs) { if (codec.FormatID == format.Guid) { return codec; } } // Return return null; } } </code></pre> <p>This is the part that generates the image.</p> <pre><code>WebsiteToImage w = new WebsiteToImage("http://nautilus/maint_responsibility/rpt_summary.aspx?lease_code=TL01306"); MemoryStream myMemoryStream = new MemoryStream(); w.Generate().Save(myMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); </code></pre> <p>If its changed to <a href="http://www.google.com.au" rel="nofollow noreferrer">http://www.google.com.au</a> or another application in house it works .... realy struggling to figure this out</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload