Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Printing rendered HTML without a browser

Options
  • 08-01-2009 7:49pm
    #1
    Registered Users Posts: 2,931 ✭✭✭


    Oki doki

    Techs: C#, ASP.NET and probably MOSS

    Scenario: I download a web page using WebClient and save it as a string. I happily send it to the the image printer and of course it prints out HTML rather than rendered.

    Had a look at using the MSHTML object but it pops up a printer dialog so thats no good to me.

    Windows.Forms has a browser control but this will be a class library that will be accessed by an ASP.NET application so I dont think I can use that.

    So has anyone got any idea on how to send a HTML string to a printer rendered as a browser would.

    At this stage I am nearly tempted to download the mozilla source and build a GUI-less version of it.

    This is to get around the whole screen shot of a page specifically web parts within MOSS and Excel Web Access. PerformancePoint provides some of this functionality as it allows you to send the sheet as an image but it is not a runner for this solution.
    Tagged:


Comments

  • Closed Accounts Posts: 167 ✭✭Deadeyes


    Could you save the string as a html file in a tmp directory and then use the Windows ShellExecute api?


  • Registered Users Posts: 1,045 ✭✭✭Bluefrog


    That seems like an interesting challenge (but probably mainly because I don't have to do it myself :D) - maybe you will find something useful here - http://smallsharptools.com/Projects/WebPreview/.


  • Closed Accounts Posts: 198 ✭✭sh_o


    Not sure if this would work for your case... I use PDFCreator to batch convert and print a large number of html files as they are exported from a different system

    What you can do is you set pdfcreator up through its UI so that the options are it prints to a particular printer automatically after saving the file (which you do once only.

    You can then call PDFCreator on the command line through a script:
    ...
    cd C:\Program Files\PDFCreator
    PDFCreator.exe /ClearCache
    PDFCreator.exe /PF"C:\.....\*.html"


    Might be easier than adapting the mozilla source!


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Bluefrog wrote: »
    That seems like an interesting challenge (but probably mainly because I don't have to do it myself :D) - maybe you will find something useful here - http://smallsharptools.com/Projects/WebPreview/.

    After looking at the source for the preview generator, it is using the following code
    
     private Bitmap GetPreviewImage()
            {
                WebBrowser wb = new WebBrowser();
                wb.ScrollBarsEnabled = false;
                wb.Size = new Size(Width, Height);
                wb.ScriptErrorsSuppressed = true;
                wb.NewWindow += new System.ComponentModel.CancelEventHandler(wb_NewWindow);
                wb.Navigate(_url);
                // wait for it to load
                while (wb.ReadyState != WebBrowserReadyState.Complete)
                {
                    Application.DoEvents();
                }
                Bitmap bitmap = new Bitmap(Width, Height);
                Rectangle rect = new Rectangle(0, 0, Width, Height);
                wb.DrawToBitmap(bitmap, rect);
                return bitmap;
            }
    

    And this is inside a class lib, I am wondering if it is possible to use the WebBrowser control in such a manner as used above..

    Could be what I need..

    When I get it working I will let you what I am allowed to :)


  • Registered Users Posts: 1,045 ✭✭✭Bluefrog


    Well the problem is that you will need something that will render the markup no matter how you do this. The demo on that site worked (albeit slowly). PDFCreator may take care of the printing part but how would it handle the rendering?


  • Advertisement
  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Bluefrog wrote: »
    Well the problem is that you will need something that will render the markup no matter how you do this. The demo on that site worked (albeit slowly). PDFCreator may take care of the printing part but how would it handle the rendering?


    using the WebBrowser object.. it renders it as a normal browser would ..

    I was looking at ActiveX but dont want to go down that road just yet as it can be very annoying with certs, and the Killbits in IE7


  • Closed Accounts Posts: 2,917 ✭✭✭towel401


    with the constantly changing nature of web browsers and increasing complexity (bloat) of most webpages this is going to be a pain in the arse


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Oh hell yeah... and it will be against a MOSS 2007 Excel Web Access web part :)


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Using the WebBrowser control, it prints a blank image..

    Hmmm .. will continue with it


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Figured out why there is no actual contents being printed, its because the browser cannot send WM_PAINT handle due to it being in a class lib by the looks of it


  • Advertisement
  • Registered Users Posts: 1,045 ✭✭✭Bluefrog


    Hmmm, might be or it might be that the asp.net user has no access to printers. When I was Googling the link above I came across a post about that particular issue without resolution.


  • Registered Users Posts: 2,931 ✭✭✭Ginger


    You can give them granular access to the printers.. tho I might try that and see if that is the issue


Advertisement