[Solved] Export Panel with Image to PDF Error: Failed to load PDF document in ASP.Net

Last Reply 3 days ago By kalpesh

Posted 4 days ago

Hi I tried to export asp panel to pdf. But error occurred "Failed to load PDF document." any help would be greatly appreciated.

using SelectPdf;
using System.Net;
using System.IO;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Drawing;
public partial class SevenPointCheckList : System.Web.UI.Page
{   
    string mainID;
  
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            mainID = Convert.ToString(Request.QueryString["ID"]);
            if (!IsPostBack)
            {
                
               // form1.InnerText = @"<html> <body>  Hello World from selectpdf.com. </body></html>";
                
                fillDropDown();
                fillBranchDetails();
                ViewState["FormMode"] = mainID;
                if (mainID == null)
                {
                    mainID = "0";
                }
                if (mainID == "0")
                {
                    ClearData();
                }
                else
                {
                    DisplayData(mainID);
                }
                if (Request.QueryString["chk"] == "P")
                {
                    ScriptManager.RegisterStartupScript(Page, this.GetType(), "PrintOperation", "printing()", true);
                    Cancel.Visible = false;
                    btnSave.Visible = false;
                    ddlCFSName.Visible = false;
                    lblCFSName.Visible = true;
                    ddlContainerNo.Visible = false;
                    lblContainerNo.Visible = true;
                    ddlLine.Visible = false;
                    lblLine.Visible = true;
                    ddlAgent.Visible = false;
                    lblAgent.Visible = true;
                    CheckBox1.Enabled = false;
                    CheckBox2.Enabled = false;
                    CheckBox3.Enabled = false;
                    CheckBox4.Enabled = false;
                    CheckBox5.Enabled = false;
                    CheckBox6.Enabled = false;
                    CheckBox7.Enabled = false;
                    CheckBox8.Enabled = false;
                    CheckBox9.Enabled = false;
                    CheckBox10.Enabled = false;
                    CheckBox11.Enabled = false;
                    CheckBox12.Enabled = false;
                    CheckBox13.Enabled = false;
                    CheckBox14.Enabled = false;
                    CheckBox15.Enabled = false;
                }
                if (Request.QueryString["chk"] == "PDF")
                {
                    Cancel.Visible = false;
                    btnSave.Visible = false;
                    ddlCFSName.Visible = false;
                    lblCFSName.Visible = true;
                    ddlContainerNo.Visible = false;
                    lblContainerNo.Visible = true;
                    ddlLine.Visible = false;
                    lblLine.Visible = true;
                    ddlAgent.Visible = false;
                    lblAgent.Visible = true;
                    CheckBox1.Enabled = false;
                    CheckBox2.Enabled = false;
                    CheckBox3.Enabled = false;
                    CheckBox4.Enabled = false;
                    CheckBox5.Enabled = false;
                    CheckBox6.Enabled = false;
                    CheckBox7.Enabled = false;
                    CheckBox8.Enabled = false;
                    CheckBox9.Enabled = false;
                    CheckBox10.Enabled = false;
                    CheckBox11.Enabled = false;
                    CheckBox12.Enabled = false;
                    CheckBox13.Enabled = false;
                    CheckBox14.Enabled = false;
                    CheckBox15.Enabled = false;

                    Response.ContentType = "application/pdf";
                    Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    StringWriter sw = new StringWriter();
                    HtmlTextWriter hw = new HtmlTextWriter(sw);
                    PrepareControlForExport(pnl);
                    pnl.RenderControl(hw);
                    StringReader sr = new StringReader(sw.ToString());
                    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
                    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                    pdfDoc.Open();
                    htmlparser.Parse(sr);
                    pdfDoc.Close();
                    Response.Write(pdfDoc);
                    Response.End();



                    //string path = Server.MapPath("SiteAnalytics.pdf");
                    //WebClient client = new WebClient();
                    //Byte[] buffer = client.DownloadData(path);
                    //if (buffer != null)
                    //{
                    //    Response.ContentType = "application/pdf";
                    //    Response.AddHeader("content-length", buffer.Length.ToString());
                    //    Response.BinaryWrite(buffer);
                    //}
                }
            }
        }
        catch (Exception ex)
        {
            string error1 = ex.Message.Replace(((char)34).ToString(), "");
            error1 = error1.Replace(((char)39).ToString(), "");
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "Call", "alert('" + (error1.ToString()) + "')", true);
        }
    }
    private static void PrepareControlForExport(Control control)
    {
        for (int i = 0; i < control.Controls.Count; i++)
        {
            Control current = control.Controls[i];
            if (current is LinkButton)
            {
                control.Controls.Remove(current);
                control.Controls.AddAt(i, new LiteralControl((current as LinkButton).Text));
            }
            else if (current is ImageButton)
            {
                control.Controls.Remove(current);
                control.Controls.AddAt(i, new LiteralControl((current as ImageButton).AlternateText));
            }
            else if (current is HyperLink)
            {
                control.Controls.Remove(current);
                control.Controls.AddAt(i, new LiteralControl((current as HyperLink).Text));
            }
            else if (current is DropDownList)
            {
                control.Controls.Remove(current);
                control.Controls.AddAt(i, new LiteralControl((current as DropDownList).SelectedItem.Text));
            }
            else if (current is CheckBox)
            {
                control.Controls.Remove(current);
                control.Controls.AddAt(i, new LiteralControl((current as CheckBox).Checked ? " True" : " False"));
                current.Visible = true;
            }

            if (current.HasControls())
            {
                SevenPointCheckList.PrepareControlForExport(current); //pdfconverter is  class.
            }
        }
    }
    public void DisplayData(string id)
    {
        try
        {
            DataSet ds = new DataSet();
            ds = SevenPtChkList.GetData(id, "SevenPointDetailsById");
            if (ds.Tables[0].Rows.Count > 0)
            {
                ddlContainerNo.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["Container_Id"]);
                ddlLine.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["Line_Id"]);
                ddlAgent.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["Party_Id"]);
                ddlCFSName.SelectedValue = Convert.ToString(ds.Tables[0].Rows[0]["Client_Id"]);
                lblSize.Text = Convert.ToString(ds.Tables[0].Rows[0]["Size"]);
                lblType.Text = Convert.ToString(ds.Tables[0].Rows[0]["Type"]);
                CheckBox1.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_1"]);
                CheckBox2.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_2"]);
                CheckBox3.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_3"]);
                CheckBox4.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_4"]);
                CheckBox5.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_5"]);
                CheckBox6.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_6"]);
                CheckBox7.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_7"]);
                CheckBox8.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_8"]);
                CheckBox9.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_9"]);
                CheckBox10.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_10"]);
                CheckBox11.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_11"]);
                CheckBox12.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_12"]);
                CheckBox13.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_13"]);
                CheckBox14.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_14"]);
                CheckBox15.Checked = Convert.ToBoolean(ds.Tables[0].Rows[0]["Chk_15"]);
                lblBranchName.Text = Convert.ToString(ds.Tables[0].Rows[0]["Branch"]);
                lblBranchN.Text = Convert.ToString(ds.Tables[0].Rows[0]["Branch"]);
                lblBranchAddr.Text = Convert.ToString(ds.Tables[0].Rows[0]["Branch_Address"]);
                lblEmail.Text = Convert.ToString(ds.Tables[0].Rows[0]["Email"]);
                lblFax.Text = Convert.ToString(ds.Tables[0].Rows[0]["Fax"]);
                lblPhoneNo.Text = Convert.ToString(ds.Tables[0].Rows[0]["Phone_No"]);
                imgLogo.ImageUrl = Convert.ToString(ds.Tables[0].Rows[0]["Logo"]);
                imgSignature.ImageUrl = Convert.ToString(ds.Tables[0].Rows[0]["Signature"]);
                if (Convert.ToString(ds.Tables[0].Rows[0]["Phone_No1"]) != "")
                {
                    lblPhoneNo.Text = lblPhoneNo.Text + "/" + Convert.ToString(ds.Tables[0].Rows[0]["Phone_No1"]);
                }
                if (Convert.ToString(ds.Tables[0].Rows[0]["Phone_No2"]) != "")
                {
                    lblPhoneNo.Text = lblPhoneNo.Text + "/" + Convert.ToString(ds.Tables[0].Rows[0]["Phone_No2"]);
                }
                if (Request.QueryString["chk"] == "P")
                {
                    lblCFSName.Text = ddlCFSName.SelectedItem.Text;
                    lblAgent.Text = ddlAgent.SelectedItem.Text;
                    lblContainerNo.Text = ddlContainerNo.SelectedItem.Text;
                    lblLine.Text = ddlLine.SelectedItem.Text;
                }
            }
        }
        catch (Exception ex)
        {
            string error1 = ex.Message.Replace(((char)34).ToString(), "");
            error1 = error1.Replace(((char)39).ToString(), "");
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "Call", "alert('" + (error1.ToString()) + "')", true);
        }
    }
    public void fillDropDown()
    {
        try
        {
            ddlContainerNo.DataSource = MainBLL.FillDropdown("ContainerDropdown", "0");
            ddlContainerNo.DataTextField = "Container";
            ddlContainerNo.DataValueField = "ID";
            ddlContainerNo.DataBind();
            ddlContainerNo.Items.Insert(0, new System.Web.UI.WebControls.ListItem("--Select Container No--", "0"));

            ddlCFSName.DataSource = MainBLL.FillDropdown("ClientDropDown");
            ddlCFSName.DataTextField = "Company";
            ddlCFSName.DataValueField = "ID";
            ddlCFSName.DataBind();
            ddlCFSName.Items.Insert(0, new System.Web.UI.WebControls.ListItem("--Select CFS Name--", "0"));

            ddlAgent.DataSource = MainBLL.FillDropdown("CHADropDown");
            ddlAgent.DataTextField = "Party";
            ddlAgent.DataValueField = "ID";
            ddlAgent.DataBind();
            ddlAgent.Items.Insert(0, new System.Web.UI.WebControls.ListItem("--Select Agent Name--", "0"));

            ddlLine.DataSource = MainBLL.FillDropdown("LineDropDown");
            ddlLine.DataTextField = "LineOperator";
            ddlLine.DataValueField = "ID";
            ddlLine.DataBind();
            ddlLine.Items.Insert(0, new System.Web.UI.WebControls.ListItem("--Select Line Name--", "0"));
        }
        catch (Exception ex)
        {
            string error1 = ex.Message.Replace(((char)34).ToString(), "");
            error1 = error1.Replace(((char)39).ToString(), "");
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "Call", "alert('" + (error1.ToString()) + "')", true);
        }
    }
    public void fillBranchDetails()
    {
        try
        {
            DataSet ds = new DataSet();
            ds = SevenPtChkList.GetData(Convert.ToString(Session["BranchId"]), "BranchDetailsViewByID");
            if (ds.Tables[0].Rows.Count > 0)
            {
                lblBranchName.Text = Convert.ToString(ds.Tables[0].Rows[0]["Branch"]);
                lblBranchN.Text = Convert.ToString(ds.Tables[0].Rows[0]["Branch"]);
                lblBranchAddr.Text = Convert.ToString(ds.Tables[0].Rows[0]["Branch_Address"]);
                lblEmail.Text = Convert.ToString(ds.Tables[0].Rows[0]["Email"]);
                lblFax.Text = Convert.ToString(ds.Tables[0].Rows[0]["Fax"]);
                lblPhoneNo.Text = Convert.ToString(ds.Tables[0].Rows[0]["Phone_No"]);
                imgLogo.ImageUrl = Convert.ToString(ds.Tables[0].Rows[0]["Logo"]);
                imgSignature.ImageUrl = Convert.ToString(ds.Tables[0].Rows[0]["Signature"]);
                if (Convert.ToString(ds.Tables[0].Rows[0]["Phone_No1"]) != "")
                {
                    lblPhoneNo.Text = lblPhoneNo.Text + "/" + Convert.ToString(ds.Tables[0].Rows[0]["Phone_No1"]);
                }
                if (Convert.ToString(ds.Tables[0].Rows[0]["Phone_No2"]) != "")
                {
                    lblPhoneNo.Text = lblPhoneNo.Text + "/" + Convert.ToString(ds.Tables[0].Rows[0]["Phone_No2"]);
                }
            }
        }
        catch (Exception ex)
        {
            string error1 = ex.Message.Replace(((char)34).ToString(), "");
            error1 = error1.Replace(((char)39).ToString(), "");
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "Call", "alert('" + (error1.ToString()) + "')", true);
        }
    }
    
    protected void btnSave_Click(object sender, EventArgs e)
    {      
        try
        {
            string rowaffected = "0";
            DataSet dtCurrentTable = new DataSet();
            if (Convert.ToString(ViewState["FormMode"]) == "0")
            {
                rowaffected = SevenPtChkList.InsertData(ddlContainerNo.SelectedValue, Convert.ToString(Session["BranchId"]), lblSize.Text, lblType.Text, ddlCFSName.SelectedValue, ddlAgent.SelectedValue, ddlLine.SelectedValue, Convert.ToBoolean(CheckBox1.Checked), Convert.ToBoolean(CheckBox2.Checked), Convert.ToBoolean(CheckBox3.Checked), Convert.ToBoolean(CheckBox4.Checked), Convert.ToBoolean(CheckBox5.Checked), Convert.ToBoolean(CheckBox6.Checked), Convert.ToBoolean(CheckBox7.Checked), Convert.ToBoolean(CheckBox8.Checked), Convert.ToBoolean(CheckBox9.Checked), Convert.ToBoolean(CheckBox10.Checked), Convert.ToBoolean(CheckBox11.Checked), CheckBox12.Checked, Convert.ToBoolean(CheckBox13.Checked), Convert.ToBoolean(CheckBox14.Checked), Convert.ToBoolean(CheckBox15.Checked), Convert.ToString(Session["UID"]), Convert.ToString(Session["LocationID"]));
            }
            else
            {
                rowaffected = SevenPtChkList.UpdateData(Convert.ToString(ViewState["FormMode"]), ddlContainerNo.SelectedValue, Convert.ToString(Session["BranchId"]), lblSize.Text, lblType.Text, ddlCFSName.SelectedValue, ddlAgent.SelectedValue, ddlLine.SelectedValue, Convert.ToBoolean(CheckBox1.Checked), Convert.ToBoolean(CheckBox2.Checked), Convert.ToBoolean(CheckBox3.Checked), Convert.ToBoolean(CheckBox4.Checked), Convert.ToBoolean(CheckBox5.Checked), Convert.ToBoolean(CheckBox6.Checked), Convert.ToBoolean(CheckBox7.Checked), Convert.ToBoolean(CheckBox8.Checked), Convert.ToBoolean(CheckBox9.Checked), Convert.ToBoolean(CheckBox10.Checked), Convert.ToBoolean(CheckBox11.Checked), CheckBox12.Checked, Convert.ToBoolean(CheckBox13.Checked), Convert.ToBoolean(CheckBox14.Checked), Convert.ToBoolean(CheckBox15.Checked), Convert.ToString(Session["UID"]), Convert.ToString(Session["LocationID"]));
            }
            if (rowaffected != "0")
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "Save()", true);
                ClearData();
            }
        }
        catch (Exception ex)
        {
            string error1 = ex.Message.Replace(((char)34).ToString(), "");
            error1 = error1.Replace(((char)39).ToString(), "");
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "Call", "alert('" + (error1.ToString()) + "')", true);
        }
        Response.Redirect("SevenPointCheckList.aspx?ID=0");
        }
    public void ClearData()
    {        
        lblType.Text = "";        
        lblSize.Text = "";
        fillDropDown();
    }
    protected void ddlContainerNo_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            DataSet ds = new DataSet();
            ds = StuffBLL.GetDataByContainerNo(ddlContainerNo.SelectedItem.Text);
            if (ds.Tables[0].Rows.Count > 0)
            {
                lblSize.Text = ds.Tables[0].Rows[0]["ISOCode"].ToString();
                 lblType.Text= ds.Tables[0].Rows[0]["ISOType"].ToString();
            }
        }
        catch (Exception ex)
        {
            string error1 = ex.Message.Replace(((char)34).ToString(), "");
            error1 = error1.Replace(((char)39).ToString(), "");
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "Call", "alert('" + (error1.ToString()) + "')", true);
        }
    }
}

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SevenPointCheckList.aspx.cs" Inherits="SevenPointCheckList" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        table{
                margin: 0;
                padding: 0;
                border: 0;
                 padding-top: 0;
        }    
        input[type=checkbox]{
height:30px;
width:20px;

}  
    .btn-danger{color:#fff;border-color:#cf4436;background:#cf4436;text-decoration: none; 
    width: 100px;align-items: flex-start;text-align: center; cursor: default; 
    box-sizing: border-box;  border-style: solid;    border-image: initial;}
     
    </style>
    <script type="text/javascript">
        function Save() {
            $('#success').css('display', 'block');
            setInterval(function () {
                $('#success').css('display', 'none');
            }, 3000);
        }
    </script>
     <script type="text/javascript">
         function printing() {
             window.print();
         }
    </script>   

    
   
</head>
<body>
    <form id="form1" runat="server" style="margin:10px;padding:10px;">   
      
        <div>
            <center>
                 <asp:Panel ID="pnl" runat="server">
        <table style="width:800px;">
            
            <tr>
                <td rowspan="5">
                    <asp:Image ID="imgLogo" runat="server" Height="100px" Width="100px" style="float:left"/>
                </td>
            </tr>
            <tr>
                
                <th colspan="3">
                   <u><b style="font-size:22px;"> <asp:Label ID="lblBranchName" runat="server"></asp:Label></b></u>
                </th>
            </tr>
            <tr>
                <td colspan="3">  
                    <center>
                    <u><asp:Label ID="lblBranchAddr" runat="server" style="font-size:17px;"></asp:Label></u> 

                    </center>
                </td>
            </tr>
            <tr>
                           
                <td><u style="font-size:15px;"><label>Tel:-</label><asp:Label ID="lblPhoneNo" runat="server"></asp:Label></u></td>
                 <td><u style="font-size:15px;"><label>Fax:-</label><asp:Label ID="lblFax" runat="server"></asp:Label></u></td>
                 <td><u style="font-size:15px;"><label>Email:-</label><asp:Label ID="lblEmail" runat="server"></asp:Label></u></td>
                   
            </tr>  
            <tr>
                
                <td colspan="4"><center><p><u><b>"Must complete atleast two checks in each section"</b></u></p></center>
                    </td>
                </tr>          
        </table>
             
            <table style="width:800px;" cellspacing="5" cellpadding="2"> 

                <tr>
                    <td><label><b>Container No:-</b></label></td>
                     <td><label><b>Size:-</b></label></td>
                    <td><label><b>Type:-</b></label></td>
                </tr>              
                <tr>                    
                    <td><asp:DropDownList ID="ddlContainerNo" runat="server" CssClass="form-control" Width="200px" AutoPostBack="true" OnSelectedIndexChanged="ddlContainerNo_SelectedIndexChanged"></asp:DropDownList>
                        <asp:Label ID="lblContainerNo" runat="server" Width="200px" Visible="false"></asp:Label>
                    </td>
                    <td><asp:Label ID="lblSize" runat="server" Width="200px"></asp:Label></td>
                    <td><asp:Label ID="lblType" runat="server" Width="200px" ></asp:Label></td>
                </tr>
                <tr>
                    <td><label><b>CFS Name:</b></label></td>
                    <td><label><b>Agent Name:-</b></label></td>
                    <td><label><b>Line Name:-</b></label></td>
                </tr>
                <tr>
                    <td><asp:DropDownList ID="ddlCFSName" runat="server" Width="200px"></asp:DropDownList>
                        <asp:Label ID="lblCFSName" runat="server" Width="200px" Visible="false"></asp:Label>
                    </td>
                    <td><asp:DropDownList ID="ddlAgent" runat="server" Width="200px"></asp:DropDownList>
                        <asp:Label ID="lblAgent" runat="server" Width="200px" Visible="false"></asp:Label>
                    </td>
                     <td><asp:DropDownList ID="ddlLine" runat="server" Width="200px"></asp:DropDownList>
                         <asp:Label ID="lblLine" runat="server" Width="200px" Visible="false"></asp:Label>
                     </td>

                </tr>
              
            </table>
                   
            <table style="width:810px;">                
                <tr>
                    <th style="float:left;width:600px;"><u style="float:left;">Front Wall</u></th>
                    <th style="float:right;width:200px;">Checks Completed</th>
                </tr>
                 <tr>
                    <td style="float:left; width:600px;"><li>Ensure interior corner blocks are visible and not false and front block is made of corrugated material</li></td>
                    <th style="float:right; width:200px;"><asp:CheckBox ID="CheckBox1" runat="server" ></asp:CheckBox></th>
                </tr>
                 <tr>
                    <td style="float:left;width:600px;"><li>Use a 40’ chain with a marker in the middle to take an interior measurement from the front waH to the rear door of both 40-foot and 20foot containers. The 40-foot container should measure 39’5" or 12.01 meters, the 20-foot container should measure 19’4” or 5.89 meters.</li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox2" runat="server" ></asp:CheckBox></th>
                </tr>
                 <tr>
                    <td style="float:left;width:600px;"><li>Ensure ventilation holes are visible not covered or absent </li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox3" runat="server" ></asp:CheckBox></th>
                </tr>
               
                 <tr>
                    <th style="float:left;width:600px;"><u style="float:left;">Left Side</u></th>
                    <th style="float:right;width:200px;"></th>
                </tr>
                 <tr>
                    <td style="float:left;width:600px;"><li>Look for unusual repairs to structural beams  </li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox4" runat="server" ></asp:CheckBox></th>
                </tr>
               
                 <tr>
                    <th style="float:left;width:600px;"><u style="float:left;">Right Side</u></th>
                    <th style="float:right;width:200px;"></th>
                </tr>
                 <tr>
                    <td style="float:left;width:600px;"><li>Look for unusual repairs to structural beams  </li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox5" runat="server" ></asp:CheckBox></th>
                </tr>
               
                 <tr>
                    <th style="float:left;width:600px;"><u style="float:left;">Floor</u></th>
                    <th style="float:right;width:200px;"></th>
                </tr>
                 <tr>
                    <td style="float:left;width:600px;"><li>Me asure the height of the container from floor to ceiling. A 40-foot and 20-foot container should measure 7'1O” or 2.38 meters  </li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox6" runat="server" ></asp:CheckBox></th>
                </tr>
                <tr>
                    <td style="float:left;width:600px;"><li>Ensure that the floor of the container is flat. There should not be different floor height in the container. </li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox7" runat="server" ></asp:CheckBox></th>
                </tr>
                <tr>
                    <td style="float:left;width:600px;"><li>Look for unusual repairs in the floor </li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox8" runat="server" ></asp:CheckBox></th>
                </tr>
              
                 <tr>
                    <th style="float:left;width:600px;"><u style="float:left;">Celling/Roof</u></th>
                    <th style="float:right;width:200px;"></th>
                </tr>
                 <tr>
                    <td style="float:left;width:600px;"><li>Observe the distance between the top of the corner block and the top of the roof. E.g. normally the roof is slightly below or flush with the top of the corner blocks.</li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox9" runat="server" ></asp:CheckBox></th>
                </tr>
                <tr>
                    <td style="float:left;width:600px;"><li>Look for repairs on the celling / roof that are visible on the inside and outside of the container.</li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox10" runat="server" ></asp:CheckBox></th>
                </tr>
               
                 <tr>
                    <th style="float:left;width:600px;"><u style="float:left;">Inside / Outside poors</u></th>
                    <th style="float:right;width:200px;"></th>
                </tr>
                 <tr>
                    <td style="float:left;width:600px;"><li>Ensure that the Container door has secure and reliable locking mechanisms.</li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox11" runat="server" ></asp:CheckBox></th>
                </tr>
                 <tr>
                    <td style="float:left;width:600px;"><li>Ensure that there are not solid plates where there are usually cavities.</li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox12" runat="server" ></asp:CheckBox></th>
                </tr>
              
                 <tr>
                    <th style="float:left;width:600px;"><u style="float:left;">Outside/Undercarriage</u></th>
                    <th style="float:right;width:200px;"></th>
                </tr>
                 <tr>
                    <td style="float:left;width:600px;"><li>The Outside / Undercarriage of a container should be inspected before It enters the facility.</li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox13" runat="server" ></asp:CheckBox></th>
                </tr>
                 <tr>
                    <td style="float:left;width:600px;"><li>Look for repairs on the outside that are visible onthe Inside of the container.</li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox14" runat="server" ></asp:CheckBox></th>
                </tr>
                 <tr>
                    <td style="float:left;width:600px;"><li>Use a tool to tap on the outside / undercarriage there should be a hollow sound.</li></td>
                    <th style="float:right;width:200px;"><asp:CheckBox ID="CheckBox15" runat="server" ></asp:CheckBox></th>
                </tr>
                 <tr>
                    <td style="float:left;width:500px;"></td>
                    <th style="float:right;width:300px;">Surveyor</th>
                </tr>
                <tr>
                    <td style="float:left;width:500px;"></td>
                    <th style="float:right;width:300px;"><asp:Image ID="imgSignature" runat="server" Height="50px" Width="100px"></asp:Image></th>
                </tr>
                 <tr>
                    <td style="float:left;width:500px;"></td>
                    <th style="float:right;width:300px;"><asp:Label ID="lblBranchN" runat="server" style="float:right;font-size:15px"></asp:Label></th>
                </tr>
            </table>
                      </asp:Panel>
            <table>
                <tr>
                    <td>
                        <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" Style="height: 25px;"></asp:Button>
                          <a id="Cancel" href="SevenPointChkList.aspx" class="btn-danger" accesskey="x" runat="server">Cancel</a> 
                    </td>
                </tr>
            </table>
    </center>
        </div>
           
    </form>
</body>
</html>

Thank you.

Posted 4 days ago

I tried with your same design and same code. It work fine if i set the image url as in correct format of path. eg.if i use https://static.flickr.com/66/199481236_dc98b5abb3_s.jpg as url also for local Path location i used one fuction to get the image location as per the file name for its full path from location if its exist folder of current application.

So be sure if is there any issue generating to PDF by missing any information which throwing the error or the image url issue while exporting to PDF.

If you problem for image url while converting to pdf then check below code for your reference.

Gayatri says:
imgLogo.ImageUrl = Convert.ToString(ds.Tables[0].Rows[0]["Logo"]);
                imgSignature.ImageUrl = Convert.ToString(ds.Tables[0].Rows[0]["Signature"]);

 

imgLogo.ImageUrl = GetUrl(Convert.ToString(ds.Tables[0].Rows[0]["Logo"]));
imgSignature.ImageUrl = GetUrl(Convert.ToString(ds.Tables[0].Rows[0]["Signature"]));

 GetUrl Function

public static string GetUrl(string pageName)
{
    string[] splits = HttpContext.Current.Request.Url.AbsoluteUri.Split('/');
    if (splits.Length >= 2)
    {
        string url = splits[0] + "//";
        for (int i = 2; i <= splits.Length - 2; i++)
        {
            url += splits[i];
            url += "/";
        }
        return url + pageName;
    }
    return pageName;
}

Screenshot


Posted 3 days ago Modified on 3 days ago

As its design issue you need to handle it by yourself as its page design for Page as well as For Pdf design so you can maintain the design view in both format.

When you will paste this content in text file and save it as htm extension it will show in proper format just one problem will arise if the image height width not in proper format as it just converting the panel content to pdf i think for image size it not get sets as per the design format so it sets by its original height and width.

If issue is related to image resize then you can solve it by creating temporary image while exporting panel content to PDF and resize it to temporary image then sets the image url to control and after pdf get generated you can set original url to it.

You can just create temporary image with resizing from original image for temporary purpose till the pdf get generated then you can assign the temporary file path to image and then you can print it.

If your issue for image then just check the below code for you reference and try for change if it work for you if any other design issue then you need to solve it by your design logic.

C#

                if (Request.QueryString["chk"] == "PDF")
                {
                    Cancel.Visible = false;
                    btnSave.Visible = false;
                    ddlCFSName.Visible = false;
                    lblCFSName.Visible = true;
                    ddlContainerNo.Visible = false;
                    lblContainerNo.Visible = true;
                    ddlLine.Visible = false;
                    lblLine.Visible = true;
                    ddlAgent.Visible = false;
                    lblAgent.Visible = true;
                    CheckBox1.Enabled = false;
                    CheckBox2.Enabled = false;
                    CheckBox3.Enabled = false;
                    CheckBox4.Enabled = false;
                    CheckBox5.Enabled = false;
                    CheckBox6.Enabled = false;
                    CheckBox7.Enabled = false;
                    CheckBox8.Enabled = false;
                    CheckBox9.Enabled = false;
                    CheckBox10.Enabled = false;
                    CheckBox11.Enabled = false;
                    CheckBox12.Enabled = false;
                    CheckBox13.Enabled = false;
                    CheckBox14.Enabled = false;
                    CheckBox15.Enabled = false;                    

                    string imageLogoUrl = imgLogo.ImageUrl;
                    string imageSignatureUrl = imgSignature.ImageUrl;

                    imgLogo.ImageUrl = SetImageAsThumbnail(imageLogoUrl, imgLogo, 100, 100, "TempLogo");
                    imgSignature.ImageUrl = SetImageAsThumbnail(imageSignatureUrl, imgLogo, 100, 50, "TempSignature");

                    Response.ContentType = "application/pdf";
                    Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    StringWriter sw = new StringWriter();
                    HtmlTextWriter hw = new HtmlTextWriter(sw);
                    PrepareControlForExport(pnl);
                    pnl.RenderControl(hw);
                    StringReader sr = new StringReader(sw.ToString());
                    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
                    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                    pdfDoc.Open();
                    htmlparser.Parse(sr);
                    pdfDoc.Close();
                    Response.Write(pdfDoc);
                    Response.End();

                    imgLogo.ImageUrl = imageLogoUrl;
                    imgSignature.ImageUrl = imageSignatureUrl;
                }

 Method to set Temporary Image as Thumbnail size.

    private string SetImageAsThumbnail(string path, System.Web.UI.WebControls.Image image1, int width, int height, string fileName)
    {
        string filePathUrl = "";
        System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("Upload_Images/" + path.Split('/')[path.Split('/').Length - 1]));
        using (System.Drawing.Image thumbnail = image.GetThumbnailImage(width, height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero))
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                thumbnail.Save(memoryStream, ImageFormat.Png);
                Byte[] bytes = new Byte[memoryStream.Length];
                memoryStream.Position = 0;
                memoryStream.Read(bytes, 0, (int)bytes.Length);
                string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
                //image1.ImageUrl = "data:image/png;base64," + base64String;

                //Convert Base64 Encoded string to Byte Array.
                byte[] imageBytes = Convert.FromBase64String(base64String);

                //Save the Byte Array as Image File.
                string filePath = Server.MapPath("~/Upload_Images/" + fileName + ".png");
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.WriteAllBytes(filePath, imageBytes);
                filePathUrl = filePath;
            }
        }
        return filePathUrl;
    }

    public bool ThumbnailCallback()
    {
        return false;
    }
I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html