2017-02-26 7 views
0

複数のプラグインとC#クラスを試して、asp.netプロジェクトのHTMLとCSSをpdfに変換しようとしました。他の関数、私はちょうど動作するようにPDF関数に任意のHTMLを取得するように見えることはできません。誰かがこれに遭遇しましたか、それを解決するために逃した何かがあるかどうかを知っていますか?HTMLをPDFに変換する

は、これは私がC#でhiqpdfのためにしようとした最新のコードです:それは、直接法のtheHiQpdfドキュメント内明記されていない

protected void Print_Button_Click(object sender, EventArgs e) 
{ 


    HtmlToPdf htmlToPdfConverter = new HtmlToPdf(); 

    // set PDF page size, orientation and margins 
    htmlToPdfConverter.Document.PageSize = PdfPageSize.A4; 
    htmlToPdfConverter.Document.PageOrientation = PdfPageOrientation.Portrait; 
    htmlToPdfConverter.Document.Margins = new PdfMargins(0); 

    // convert HTML to PDF 
    htmlToPdfConverter.ConvertUrlToFile("http://localhost:51091/Printout","mcn.pdf"); 


} 
+0

これは機能しないとはどういう意味ですか?エラー?より具体的にしてください。 –

+0

こんにちは@SamKuhmonen、私はコードを実行すると何も起こりません – kehoewex86

答えて

0

が、方法ConvertUrlToFile()店ディスク上の地元産のpdfファイル。ファイルはおそらく生成され、あなたの例以来

 // ConvertUrlToFile() is called to convert the html document and save the resulted PDF into a file on disk 
     // Alternatively, ConvertUrlToMemory() can be called to save the resulted PDF in a buffer in memory 
     htmlToPdfConverter.ConvertUrlToFile(url, pdfFile); 

は、ボタンクリックイベントハンドラを示してではなく、HTTPに戻すために使用:いくつかの例のページで、次のコメントを見つけることができます(PDFへのURLやHTMLコードを変換)応答。応答にデータを書き込む必要があります。方法ConvertToStream()またはConvertToMemoryは便利です。それ以前はResponse.Clear()またはResponse.ClearContent()Response.ClearHeader()、その後はFlush() and Close()を使用することを忘れないでください。

関連する問題