2017-02-26 1 views
0

이것은 hiqpdf 용으로 다운로드 한 C#입니다. 그러나 HTML을 수정하는 방법을 잘 모르겠습니다. 오류 오 om 내 asp.net C#을 textBoxUrl 시트오고 있지만이 네가 잡아야 사용해야 또는 네가이 텍스트를 바꿀 필요가 있는지 잘 모르겠다?hiqpdf - asp.net - div를 캡처하는 코드를 수정하는 방법

C# 코드 :

using HiQPdf; 

protected void Print_Button_Click(object sender, EventArgs e) 
{ 

    // create the HTML to PDF converter 
    HtmlToPdf htmlToPdfConverter = new HtmlToPdf(); 

    // select the HTML element to be converted to PDF 
    htmlToPdfConverter.ConvertedHtmlElementSelector = 
            textBoxConvertedHtmlElementSelector.Text; 

    // convert URL to a PDF memory buffer 
    string url = textBoxUrl.Text; 

    byte[] pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url); 

    // inform the browser about the binary data format 
    HttpContext.Current.Response.AddHeader("Content-Type",application/pdf"); 

    // let the browser know how to open the PDF document 
    HttpContext.Current.Response.AddHeader("Content-Disposition", 
       String.Format("attachment; filename=ConvertHtmlPart.pdf; 

         size ={ 0} 
    ", 
     pdfBuffer.Length.ToString())); 

    // write the PDF buffer to HTTP response 
    HttpContext.Current.Response.BinaryWrite(pdfBuffer); 

    // call End() method of HTTP response 
    // to stop ASP.NET page processing 
    HttpContext.Current.Response.End(); 

} 

답변

0

textBoxUrl는 TextBox 컨트롤이다. 이것을 소스 URL로 대체해야합니다.

예 : "#page"선택기가있는 bbc 사이트 용.

using HiQPdf; 

protected void Print_Button_Click(object sender, EventArgs e) 
{ 

// create the HTML to PDF converter 
HtmlToPdf htmlToPdfConverter = new HtmlToPdf(); 

// select the HTML element to be converted to PDF 
htmlToPdfConverter.ConvertedHtmlElementSelector = "#page"        

// convert URL to a PDF memory buffer 
string url = "http://www.bbc.com/"; 

byte[] pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url); 

// inform the browser about the binary data format 
HttpContext.Current.Response.AddHeader("Content-Type",application/pdf"); 

// let the browser know how to open the PDF document 
HttpContext.Current.Response.AddHeader("Content-Disposition", 
      String.Format("attachment; filename=ConvertHtmlPart.pdf; 

        size ={ 0} 
", 
    pdfBuffer.Length.ToString())); 

// write the PDF buffer to HTTP response 
HttpContext.Current.Response.BinaryWrite(pdfBuffer); 

// call End() method of HTTP response 
// to stop ASP.NET page processing 
HttpContext.Current.Response.End(); 

}