1
Private Sub document_PrintPage(ByVal sender As Object, _
   ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
       Handles docToPrint.PrintPage

    ' Insert code to render the page here.
    ' This code will be called when the control is drawn.

    ' The following code will render a simple
    ' message on the printed document.
    'Dim text As String = "In document_PrintPage method."
    'Dim printFont As New System.Drawing.Font _
    '    ("Arial", 35, System.Drawing.FontStyle.Regular)

    '' Draw the content.
    'e.Graphics.DrawString(text, printFont, _
    '   System.Drawing.Brushes.Black, 10, 10)
End Sub

I have code to display a printer dialog box that will call this procedure to render a document for printing. The document I want to print is accessible from a URL as an HTML webpage, and the webpage is understood to be available for printing. The sample code above, for rendering strings only, will not do what I need. I was thinking of using system.drawing.graphics.drawimage, if that can be made to work. Any ideas? I'm having trouble fully picturing the process of converting the HTML page to an image datatype. If that's not necessary, all the better.

2 Answers2

0

Is there any reason you can't use System.Windows.Forms.WebBrowser?

It has a Print() method, which would seem to make your task easier. . . 8-)

Rendering HTML into an image for printing is not a trivial task. One way or the other you'll need to leverage a library that knows how to do it.

Terry Carmen
  • 3,720
  • 1
  • 16
  • 32
  • Thanks for your answer PushPopf. The code above would have been useless for my actual needs, but it wasn't apparent that was the case due to running the code in a vb .net IDE debugger. This needs to be something I can call from a remotely activated webpage, and the code above only runs server-side. I switched to a javascript print box for the remotely displayed printer dialog. I have the current status of this posted as my ANSWER. – Earl Patrick Dean Jul 28 '16 at 18:47
0

First I changed my printer dialog call so that it runs client side by using a javascript function. That was easy. The next thing was to isolate the area to be printed to the rectangle enclosing the satellite map loaded as source into an iframe. As my understanding is the javascript printer dialog would dump the whole page to the printer, I tried several things and eventually enclosed the iframe in its own div section on the asp panel that has the html button tag that calls the printer dialog and the iframe. This was enough to get only the map printed. One thing that may be necessary to allow this is that you need to use subdomains to trick the browser into thinking the iframe host and the document host are on the same domain-- I had already worked with the mapping company and our local hosting company to get that part done. The only thing left to do is to get the iframe to hold a selected zoom status of the map when I click to open the printer dialog. I will post another question for opinions on how to get an asp panel to freeze its view, or whatever other trick might enable that.

  • I was able to test the javascript printing of our mapping iframe tonight at home. My concern about the iframe refresh zooming out as I click the html button for printing was apparently for no reason-- the image is sent to the printer before the zoom-out occurs: I can get a snapshot of the map at any level of zoom. This is all I needed-- I think this is either done as-is or will be as soon as I can get the mapping applet to show the map without the mapping toolbars surrounding it. As of right now, the toolbars can be retracted with a mouse click. – Earl Patrick Dean Jul 29 '16 at 00:51