0
aspx 페이지를 pdf로 내보내고 다운로드 할 때 몇 가지 문제가 있습니다. 코드는 다음과 같습니다.aspx 웹 페이지를 pdf로 다운로드하여 다운로드하십시오.
protected void Button1_Click(object sender, EventArgs e)
{
string url = Request.Url.AbsoluteUri;
using (StreamReader reader = new StreamReader(Server.MapPath(url)))
{
String line = reader.ReadToEnd();
Text2PDF(line);
}
}
protected void Text2PDF(string PDFText)
{
//HttpContext context = HttpContext.Current;
StringReader reader = new StringReader(PDFText);
//Create PDF document
Document document = new Document(PageSize.A4);
HTMLWorker parser = new HTMLWorker(document);
string PDF_FileName = Server.MapPath("MyFirstPdf.pdf");
PdfWriter.GetInstance(document, new FileStream(PDF_FileName, FileMode.Create));
document.Open();
try
{
parser.Parse(reader);
}
catch (Exception ex)
{
//Display parser errors in PDF.
Paragraph paragraph = new Paragraph("Error!" + ex.Message);
Chunk text = paragraph.Chunks[0] as Chunk;
if (text != null)
{
text.Font.Color = BaseColor.RED;
}
document.Add(paragraph);
}
finally
{
document.Close();
DownLoadPdf(PDF_FileName);
}
}
private void DownLoadPdf(string PDF_FileName)
{
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(PDF_FileName);
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
그러나 버튼을 클릭해도 아무런 변화가 없습니다. 브라우저에서 다운로드하라는 메시지를 표시하지 않습니다. 이유가 궁금합니다. 미리 감사드립니다.
로 트리거를 추가하고 난 당신이 내가 영문 파일 내 버튼을 선언 한 후 위의 줄을 추가 의미 – Damith
당신이 당신의 페이지 내에서 UpdatePanel을 사용하는 생각하십시오 그렇지 않으면. 아니요 업데이트 패널을 사용하지 않았습니다 –
업데이트 패널을 사용해야합니까? –