You must Sign In to post a response.
  • Category: .NET

    How to fit image top of report generated in pdfdoc in iframe

    below is my code i have set image to pdfdoc in iframe but that image is oming down of report in pdfdoc
    i have also written
    img.Alignment = Element.ALIGN_TOP;but not working
    so any body plz suggest where i am wrong
    protected void bt11_Click(object sender, EventArgs e)
    {
    //Document myDoc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 50, 50);
    //try
    //{

    string cs = "Data Source=HOME;Initial Catalog=Registration;Integrated Security=True";
    SqlConnection con = new SqlConnection(cs);
    SqlCommand cmd = new SqlCommand("select * from employeep where Salary" + DropDownList1.SelectedValue + "", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    GridView1.DataSource = ds;
    GridView1.DataBind();
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    string imageURL = Server.MapPath("naree.jpg");
    string Filepath = Server.MapPath("~report.pdf");
    //string imageURL = Server.MapPath("/reports.jpg");

    iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imageURL);
    img.ScaleToFit(80f, 80f);

    //Align image to the TOP
    img.Alignment = Element.ALIGN_CENTER;



    FileStream fs = new FileStream(Filepath, System.IO.FileMode.Create);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);

    GridView1.RenderControl(hw);

    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
    //Document pdfDoc = new Document(PageSize.A4, 0f,0f, 0f,0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, fs);
    pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Add(img);
    pdfDoc.Close();
    fs.Close();
    GridView1.Visible = false;
    iframepdf.Attributes.Add("src", "~report.pdf");

    }
  • #762036
    Hello Velidiviram,

    There is no problem with your code.

    Try to use these lines together and make it try :

    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, fs);
    pdfDoc.Open();
    img.ScaleToFit(80f, 80f);
    img.Alignment = Element.ALIGN_TOP;
    htmlparser.Parse(sr);
    pdfDoc.Close();


    Hope this will work for you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


Sign In to post your comments