i just want to see all the report on a pdf format on button click. i use ...
protected void Button1_Click(object sender, EventArgs e)
{
//Create Document class object and set its size to letter and give space left, right, Top, Bottom Margin
Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
//Write some content
Paragraph paragraph = new Paragraph("This is my first line using Paragraph.");
Phrase pharse = new Phrase("This is my second line using Pharse.");
Chunk chunk = new Chunk(" This is my third line using Chunk.");
// Now add the above created text using different class object to our pdf document
doc.Add(paragraph);
doc.Add(pharse);
doc.Add(chunk);
doc.Close(); //Close document
}
but not effective开发者_如何学运维
Your button click is simply creating a document in memory, writing to it and closing it.
You need to output the document to the Response.Output
stream.
This works for me:
protected void PrintButton_Click(object sender, EventArgs e)
{
if (!Page.IsValid) return;
Response.ContentType = "application/pdf";
using (var document = new Document())
{
PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
document.Add(new Paragraph("Hello PDF!"));
document.Close();
}
}
The main thing that you were missing was the PdfWriter which writes the document to the Response.OutputStream
精彩评论