2014-09-15 9 views
1
내가 HTML을 PDF로 내보낼

을 생성, 문서가 생성됩니다 만 첫 페이지HtmlOption.Engine은 첫 페이지

Doc theDoc = new Doc(); 
    theDoc.HtmlOptions.UseScript = true; 
    theDoc.HtmlOptions.Media = MediaType.Print; 
    theDoc.HtmlOptions.InitialWidth = 1048; 
    theDoc.HtmlOptions.ImageQuality = 101; 
    theDoc.HtmlOptions.UseScript = true; 
    theDoc.HtmlOptions.OnLoadScript = "(function(){ window.ABCpdf_go = false; setTimeout(function(){ window.ABCpdf_go = true; }, 55000); })();"; 
    theDoc.HtmlOptions.Engine = EngineType.Gecko; 
    theDoc.HtmlOptions.PageLoadMethod = PageLoadMethodType.WebBrowserNavigate; 
    theDoc.HtmlOptions.ForMSHtml.UseScript = true; 

    int theID = theDoc.AddImageHtml(htmlContent); 

    while (true) 
    { 
     theDoc.FrameRect(); 
     if (!theDoc.Chainable(theID)) 
      break; 
     theDoc.Page = theDoc.AddPage(); 
     theID = theDoc.AddImageToChain(theID); 
    } 
    for (int i = 1; i <= theDoc.PageCount; i++) 
    { 
     theDoc.PageNumber = i; 
     theDoc.Flatten(); 
    } 

    theDoc.Save(HttpContext.Current.Server.MapPath("htmlimport.pdf")); 
    theDoc.Clear(); 

게코 모든 페이지를 어떻게 할 수있는 추가? 나는 Gekoengine을 사용하려면

+0

작동하도록 설정 했습니까? 나는 같은 문제가 있는데, 아래에 허용 된 대답은 아무것도 추가하지 않는 것 같습니다. 감사 – user1259167

답변

1

잘 보이지 된 페이지에서 MSHTML 스타일을 사용하는 경우, 상단의 문서 설정에

theDoc.HtmlOptions.Engine = EngineType.Gecko; 

를 추가합니다.

HTML을 추가 할 때 문서를 페이징해야합니다. 루프에있는 내용을 감싸고, 최대 한도를 50 페이지로 설정했지만, 문서가 루프 위로 올라간 경우 문서를 처리해야합니다.

int theID = theDoc.AddImageUrl(htmlContent); 
//Add up to 50 pages 
for (int i = 1; i <= 50; i++) 
{ 
    if (!theDoc.Chainable(theID)) 
    break; 
    theDoc.Page = theDoc.AddPage(); 
    theID = theDoc.AddImageToChain(theID); 
}