Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8186405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:11:05+00:00 2026-06-07T02:11:05+00:00

I have trouble with the printing function of the WebBrowser control. First i load

  • 0

I have trouble with the printing function of the WebBrowser control.

First i load my page and it is rendered correct.
Then i set the header/footer/margins and the right printer:
webbrowser printing;
How do I programatically change printer settings with the WebBrowser control?

That works so far. Then i use myBrowser.Print();

But my website does not print right. Only the upper left corner is printed, a few centimeters and then there are scrollbars.

I printed my website with the IE9 and everything was alright. Also tried different browsermodes and documentmodes. No problem.
And i thought the control and the IE are technically the same…

Are there any parameters i have forgotten?

The website i want to print is old and has no doctype. But since the control displays it correct, I expect it to print correct, too.

Edit:

Found out that it has to do with javascript on the website, which does not run for printing.
Is there a way to get the HTML from the manipulated DOM?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:11:06+00:00Added an answer on June 7, 2026 at 2:11 am

    For the print function no external documents are processed. All documents for a website have to be merged into one printable site. To get the other documents you have to cast the myBrowser.Document.DomDocument to an IHTMLDocument2. From that IHTMLDocument2 you can extract the CSS or JS to put it into the html.

    For Example:

        void myBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            myBrowser.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(myBrowser_DocumentCompleted);
            myBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(myBrowser_DocumentPrintable);
            String mySource = myBrowser.DocumentText;
    
            // Get the CSS
            IHTMLDocument2 doc = (myBrowser.Document.DomDocument) as IHTMLDocument2;
            myCSS = doc.styleSheets.item(0).cssText;
            mySource = mySource.Replace("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/style.css\">", "<style type=\"text/css\">"+myCSS+"</style>");
    
            // Reload
            myBrowser.DocumentText = mySource;
        }
    
        void myBrowser_DocumentPrintable(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            myBrowser.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(myBrowser_DocumentPrintable);
            myBrowser.Print();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have having some trouble printing a char from an ASCII value stored in
I am having trouble printing out individual Strings from Interable object. I have this
I have trouble figuring out why a simple division like this one always returns
We have trouble implementing a nice session mechanism in JSP. One of our requirement
I have trouble with strange behavior of for..in cycle in JavaScript. I have the
I have trouble doing this... You may want to get the same result as
I have trouble shooting at file download problem. In Chrome, the download works fine.
I have trouble accessing filestream via SqlFileStream. Sql server and IIS7 are on different
I have trouble where, for some reason, SVN would only merge the newly generated
I have trouble launching Glassfish v3 on Mac In Windows, after installation of Glassfish

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.