2017-02-26 5 views
0

これはhiqpdf用にダウンロードしたC#ですが、HTMLを修正する方法はわかりません。私の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(); 

} 
関連する問題