itextsharp を使用して、html ページ ビューから pdf ファイルを作成しようとしています。
このコード ブロックは機能しますが、url から html コード文字列を取得し、この文字列を変換する必要があります。そのため、関数に url を指定することで、任意のサイト ビューを pdf に変換できます。ありがとう..
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
WebClient wc = new WebClient();
string htmlText = wc.DownloadString("http://");
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();