2014-04-29 5 views
2

HTML 문서 :인쇄 나는 다음과 같은 코드를 성공적으로 HTML 문서를 인쇄하고 있습니다

using (WebBrowser webBrowser = new WebBrowser()) 
{ 
    webBrowser.DocumentText = text; 
    while (webBrowser.ReadyState != WebBrowserReadyState.Complete) 
     Application.DoEvents(); 

    InternetExplorer internetExplorer = (InternetExplorer)webBrowser.ActiveXInstance; 
    internetExplorer.PrintTemplateTeardown += InternetExplorer_PrintTemplateTeardown; 
    internetExplorer.ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER); 

    while (!documentPrinted) 
     Application.DoEvents(); 

    internetExplorer.PrintTemplateTeardown -= InternetExplorer_PrintTemplateTeardown; 
} 

두 가지 문제 : 인쇄 된 용지는 헤더 (page 1 of 1)과 바닥 글을 가지고

  1. (about:blankdate). 그것들 없이는 어떻게 인쇄 할 수 있습니까?
  2. 인쇄 된 용지는 실제 HTML 페이지 내용보다 훨씬 길다. 내용이 끝나면 어떻게 인쇄를 멈출 수 있습니까?
+0

을 FYI : http://stackoverflow.com/a/19172580/1768303 – Noseratio

+0

감사합니다. 스레드는 유익하지만 인쇄중인 웹 페이지를 변경할 수 없습니다. 페이지를 변경하지 않고 해당 머리글과 바닥 글을 지우는 방법이 있습니까? – toy4fun

+0

예, 맞춤 헤더/꼬리말 (빈 것을 포함하여)을 설정할 수있는 'IDM_PRINT' 링크가 있습니다. – Noseratio

답변

4

맞춤 인쇄 템플릿을 사용하지 않고 해결책을 찾았습니다.
이 코드는 머리글과 바닥 글을 지 웁니다

열 프린터에 용지를 절단하기 위해
const string keyName = @"Software\Microsoft\Internet Explorer\PageSetup"; 

    using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true)) 
    { 
     if (key != null) 
     { 
      key.SetValue("footer", string.Empty); 
      key.SetValue("header", string.Empty); 
     } 
    } 

브라우저의 내용 끝, 나는이 라인에 PRINT_WAITFORCOMPLETION 매개 변수를 추가했습니다 :

internetExplorer.ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, Win32.PRINT_WAITFORCOMPLETION); 
+0

이 답변으로 인해 많은 시간을 절약 할 수있었습니다. 고맙습니다. –