Click here to Skip to main content
15,908,775 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
God day every one

I am having little trouble converting the information my table to pdf

i have
XML
table <table id="gv" runat="server" width="100%">
</table

there are lots of information inside, but i want to convert it to pdf on button click ..my code behind is

C#
 protected void ImgPdf_Click(object sender, ImageClickEventArgs e)
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=xport.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            gv.RenderControl(hw);
            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
             PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End(); 
        }
// but on when i reload the page and click on the button i will get this error
Exception of type 'System.Web.HttpUnhandledException' was thrown.

The URI prefix is not recognized.


//Can some one help me..I do appreciate your time..
Posted

Check the following links (most of them use third parties) -
http://www.dotnetfox.com/articles/export-html-table-to-pdf-in-Asp-Net-1092.aspx[^]
Using iTextSharp[^]
Export GridView to Pdf[^] (not for table but the concept should help)
 
Share this answer
 
USe Microsoft Primary Interop Libraries for converting DataTable to PDF.

C#
public bool ConvertWordToPdf(object source, object target)
       {
           if (_wordDocument == null)
           {
               _wordDocument = new Microsoft.Office.Interop.Word.ApplicationClass();
           }
           try
           {
             //  wordDocument.Visible = false;
               _wordDocument.Documents.Open(ref source, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown);
              // wordDocument.Application.Visible = false;
               _wordDocument.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize;
               object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
               _wordDocument.ActiveDocument.SaveAs(ref target, ref format, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown, ref _unknown);
           }
           catch (Exception e)
           {
               Console.WriteLine(e.Message);
           }
           finally
           {
               if (_wordDocument != null)
               {
                   _wordDocument.Documents.Close(ref _unknown, ref _unknown, ref _unknown);
               }
               _wordDocument.Quit(ref _unknown, ref _unknown, ref _unknown);
           }
           return true;
       }



//Use the above function as described below

C#
var obj = new ConvertMethodHelper();
           const string source = @"C:\Test\Prod20131107141635558.doc";
           const string destination = @"C:\Test\word07.pdf";
           bool checkMethodExecStatus=obj.ConvertWordToPdf(source, destination);
 
Share this answer
 

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