Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}


protected void exportPDF_Click(object sender, EventArgs e)
{

Response.ContentType = "application/pdf";
Response.AddHeader("content0disposition",
"attachment;filename=Report.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gd_dt.AllowPaging = false;
gd_dt.DataBind();
gd_dt.RenderControl(hw);
gd_dt.HeaderRow.Style.Add("width", "15%");
gd_dt.HeaderRow.Style.Add("font-size", "10px");
gd_dt.Style.Add("text-decoration", "none");
gd_dt.Style.Add("font-family", "Arial, Helvetica, sans-serif");
gd_dt.Style.Add("font-size", "8px");
StringReader sr = new StringReader(sw.ToString());
StreamReader reader = new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(sw.ToString())));
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(reader);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

}

pls help me.i'mtotally lost!

musiw.
Posted
Updated 11-Jun-12 22:18pm
v2
Comments
Sandeep Mewara 12-Jun-12 3:14am    
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.
Vani Kulkarni 12-Jun-12 4:35am    
What is the error are you encountering with?
musiw 12-Jun-12 5:05am    
the error is:the document has no page at line pdf.close(); i dont understand why

1 solution

Your question is to export html to PDF. Here is a similar discussion, please first have a check: export html to Pdf[^]
 
Share this answer
 
Comments
musiw 12-Jun-12 22:02pm    
im using spire.i get from the link you gave. btw you know how to export datatable to landscape page in pdf?? right now im able to export it to pdf.but its not full.my gridview is long.in pdf it seem like it is half cut
Pandvi 12-Jun-12 22:24pm    
//Create a pdf document.
PdfDocument doc = new PdfDocument();

String url = "your url";

PdfSection section = doc.Sections.Add();
section.LoadFromHTML(url, false, true, new Spire.Pdf.HtmlConverter.PdfHtmlLayoutFormat
{
FitToHtml = Spire.Pdf.HtmlConverter.Clip.Both,
Layout = Spire.Pdf.Graphics.PdfLayoutType.OnePage
});
//Save pdf file.
doc.SaveToFile("FromHTML.pdf");
doc.Close();
System.Diagnostics.Process.Start("FromHTML.pdf");
musiw 12-Jun-12 22:41pm    
this is the code:

SqlConnection myConnection = new SqlConnection(connectionString);
SqlCommand Command = new SqlCommand();
Command.CommandText = "select origin,report,react_delay as 'reactionary delay',responsibility,actions from signals_comm_failure where date = '" + TextBox1.Text + "' and id_class=1";
Command.Connection = myConnection;
using (SqlDataAdapter da = new SqlDataAdapter(Command))
{
DataTable dt = new DataTable();
da.Fill(dt);
gd_dt.DataSource = dt;
}
Spire.DataExport.PDF.PDFExport PDFExport = new Spire.DataExport.PDF.PDFExport();
PDFExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
PDFExport.DataTable = this.gd_dt.DataSource as DataTable;
PDFExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
PDFExport.SaveToFile("Report.pdf");

i want it to display in landscape page format.and 1 more thing; actually i have multiple gridview in multiple tab container.how can i export that multiple gridview into pdf?

the code that spire give only for 1 gridview.really hope that you can help me.
Pandvi 12-Jun-12 23:21pm    
Before you SaveToFile(), please add this line of code:

PdfExport.PDFOptions.PageOptions.Orientation = Spire.DataExport.Common.PageOrientation.Landscape;
musiw 13-Jun-12 0:22am    
done.i already done that line.it works. but 1 more thing, how to export multiple gridview to pdf.the code only convert 1 gridview

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900