Click here to Skip to main content
15,747,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try the code for autogenerate pdf.
and my code is:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Text;

public partial class pdf : System.Web.UI.Page
{
    string Date, ReportTitle;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_Click(object sender, EventArgs e)
    {
        lblSubTitle.Text = "nafisa";
        Response.Clear();
        Response.Buffer = true;
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=" + lblSubTitle.Text.Replace(" ", "_").Replace("<br />", "") + "_" + DateTime.Now.Date.ToString("dd-MM-yyyy") + ".pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        //gvReport.AllowPaging = false;
        ////gvReport.DataBind();
        //gvReport.RenderControl(hw);
        ReportTitle = lblSubTitle.Text;
        Date = lblDate.Text;
        // string content = "<div align="center" style="font-family:verdana;font-size:13px"><span style="font-size:13px;">" + ReportTitle + "</span><br /><br /><span style="font-size:8px:font-weight:bold">" + sw.ToString() + "</span></div>";
        string content = "<div align="center" style="font-family:verdana;font-size:13px"><span style="font-size:16px:font-weight:bold;color:Maroon">CARE MEDIQUIP</span><br /><br /><span style="font-size:13px:font-weight:bold">" + ReportTitle + "</span><br /><br /><div align="right" style="font-family:verdana;font-size:11px"><strong>Date :</strong>" + Date + "</div><br />" + sw.ToString() + "</div>";
         Response.Output.Write(content);

        StringReader sr = new StringReader(content);
        Document pdfDoc = new Document(PageSize.A3, 10f, 10f, 10f, 0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        // htmlparser.Parse(lblSubTitle.Text);
       htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }
}

I get the error

Server Error in '/Question' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for 'iTextSharp.text.html.simpleparser.HTMLWorker.Parse(System.IO.StreamReader)' has some invalid arguments

Source Error:

Line 40:         PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
Line 41:         pdfDoc.Open();
Line 42:         htmlparser.Parse(sr);
Line 43:        
Line 44:         pdfDoc.Close();
Source File: d:\Question\pdffile.aspx.cs    Line: 42

Show Detailed Compiler Output:
Show Complete Compilation Source:
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 

so help me plz to solve this errror!
Posted
Updated 4-Jul-12 3:57am
v2
Comments
[no name] 4-Jul-12 9:01am    
sr should be a StreamReader not a StringReader.

1 solution

See this code samples: http://www.developerfusion.com/code/6623/dynamically-generating-pdfs-in-net/[^]
Or you can get help from here: http://itextpdf.com/[^]
Best Regards
 
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