Locked Question about the WebBrowser Control

  • Thursday, March 01, 2012 10:39 PM
     
     

    Hi everyone.  I have a simple HTML form that I am loading into a WebBrowser Control and injecting data into then printing.  This works very well though simplistic.  I have one minor problem that upon searching online appears to be a limitation of the WebBrowser control, but I wanted to ask here to see if anyone happened to know of a way that I could work around this issue.

    Presently, when it prints, it is printing as about:blank.  I can only assume that this is pulling this from the DocumentTitle (Which I cannot set apparently).  So, I was wondering if anyone had any ideas or suggestions that might allow me to change the name of the printed document.  I tried changing the page title and that did not solve this problem either.

    Thanks Again,

    -Matt-

All Replies

  • Monday, March 05, 2012 5:58 AM
     
     

    Hi Matt,

    Do you want to change the name of "printed document"? What about changed the name of the document before sending it to the printer?

    Thanks.

  • Monday, March 05, 2012 1:29 PM
     
     

    Thanks for your response.  I figured that was the way to do it, but as far as I can tell from searching the internet, I can get that value, but cannot set it to something...

    Do you happen to know how I can do this then?  I'm coming up with nothing useful.  :(

  • Tuesday, March 06, 2012 9:14 AM
    Moderator
     
     

    Hi Matt,

    Welcome to the MSDN forum!

    How do you load the HTML form into the WebBrowser control? Would you please show us some code relate? Also, what is the HTML form here? 

    We can see from the document that WebBrowser.DocumentTitle is a read only property. If you want to "set" the name of the target document, you may try to set the name of the document before it is being loaded into the WebBrowser control.

    Have a nice day!

    yoyo


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

  • Tuesday, March 06, 2012 12:56 PM
     
      Has Code

    Thank you very much for the response, I really appreciate this.  The HTML is a document that I am using as a Work Order.  Basically I am filling the HTML document with information and then printing it.  I am really not sure how I would set the name of the document before it is being loaded.  The file itself is a Embedded Resource if that affects things.  :\

    Here is the code that I am using.

            private void PrintWorkOrder()
            {
                //Read template into StringBuilder
                StringBuilder sb = new StringBuilder(Properties.Resources.WorkOrder);
    
                //add <pre> </pre> to string
                string p = "<pre>";
    
                //Replace Items with data
                sb.Replace("$JobType", JobTypeString);
                sb.Replace("$Name", SelectedCustomerName);
                sb.Replace("$Date", DateDTI.Text);
                sb.Replace("$Day", p + "");
                sb.Replace("$Time", TimeDTI.Text);
                sb.Replace("$Address1", LAddress1String);
                sb.Replace("$Address2", LAddress2String);
                sb.Replace("$Address3", LAddress3String);
                sb.Replace("$HPhone", HPhoneString);
                sb.Replace("$WPhone", WPhoneString);
                sb.Replace("$MPhone", MPhoneString);
                sb.Replace("$JobNotes", JobDescriptionTB.Text);
                sb.Replace("$InsuranceCompany", InsuranceCompanyString);
                sb.Replace("$JobInstructions", JobInstructionsTB.Text);
                sb.Replace("$Docs", DocsNeededTB.Text);
                sb.Replace("$Pics", PicsNeededTB.Text);
                sb.Replace("$Script", ScriptString);
    
                //Give document a pointer to the image file
                sb.Replace("$Logo", MappedDriveString + @"\Pictures\Company\1_Logo.png");
    
                //Load into browser
                ReportWebBrowser.DocumentText = sb.ToString();
            }

    Thank you very much.  :)

  • Thursday, March 08, 2012 5:51 AM
    Moderator
     
     

    Hi MyLyons,

    Thanks for your response.

    When I tested on my computer, I found that the "about:blank" at the left bottom of the page is the url of the document. Since the html document's location is local, it gives us "about: blank". When we print a remote html page from the IE, for example, the current page, we can see that the url displays at the left bottom.

    To get rid of the "about:blank", you need to configure the print. Please try the following steps:

    1.Open IE.

    2. On the current tab, right click on the page, go to the "Print Preview" item. 

    3. On the "Print Preview" dialog, click on the "Page Setup", or press "Alt+U".

    4. On the "Page Setup" dialog, go to the "Headers and Footers" panel, and under the "Footer" combobox, select "empty". We can see that the "about: blank" disappeared. Here, the "Url" is the value by default.

    Hope it helps.

    Have a nice day!

    yoyo


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

  • Thursday, March 08, 2012 2:29 PM
     
     

    Alright, I suppose I can do that.  What I was hoping to do (And believe are related) was set the name of the document when it's being printed as we often print it to PDF and would be naming these files.  It would be useful if these files had a name that shows what it is without our having to rename every file.  The Document Name is read only though, so it does not appear I can do that.  Unless there is another way to do that?

    Thanks Again for your help,

    -Matt-

  • Thursday, March 08, 2012 3:17 PM
    Moderator
     
     

    Hi Matt,

    Thanks for your response.

    I'm trying to help but I am not very sure about the issue.

    Well, there is a PrintDocument.DocumentName property which can be get and set. We can new a PrintDialog and set the PrintDocument to its Document property. 

    However, what I am not sure is "would be naming these files". Do you mean that when you save the pdf file, you need to save the file name? Or do you just want to show the file name of the content of the pdf file, like on the footer or something?

    Since as far as have I known, we can set the footer of a printed page with the configuration of Print Preview, and it may do the work for the latter.

    See: http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.documentname.aspx 

    How to: Print in Windows Forms Using Print Preview

    http://msdn.microsoft.com/en-us/library/ms404294.aspx#Y100

    Let me know if you need any help.

    Regards,

    yoyo


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us





  • Friday, March 09, 2012 2:32 PM
     
     

    Hi, thank you for your response.  I'm sorry if I was unclear...  :|

    I am loading this html document into a webBrowser control for the sole purpose of printing it.  This works fine, but I would like to designate a name for the file when I send it to the printer.  Currently the file name is set to about:blank.  Usually these documents end up being printed to a PDF, so in that case the document name does matter and rather than requiring the user to type in a detailed name, I would like to generate that myself so it would be like "SelectedCustomer + "_" + "Work Order""...  I've not found a way to do this though as it appears to pull this from the DocumentTitle property which I can't set as we've already discussed...  I'm not really sure how else I can do something like this and haven't been able to figure any alternative out.

    Thanks Again for all of your help.  I really do appreciate it.

    -Matt-

  • Monday, March 12, 2012 9:22 AM
    Moderator
     
     Answered

    Hi Matt,

    Here, the "about:blank" is actually the URL of the HTML document inside the WebBrowser.  You can check it through WebBrowser.Document.Uri property.   Since we are using DocumentText to set the WebBrowser content directly, we cannot set its URL then, let alone customize the content.  

    For the DocumentTitle, its actually the HTML title for the HTML document.   It's set inside the HTML codes.   <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><html><head><title>Hello World</title></head><body>Hello World</body></html>

    So I am afraid that your request can not be fulfilled easily.

    Good day!


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us