Click here to Skip to main content
11,489,693 members (68,068 online)
   

C#

 
GeneralRe: How do they do this when copying files? Pin
PHS2412-May-13 2:23
memberPHS2412-May-13 2:23 
AnswerRe: How do they do this when copying files? Pin
Abhinav S2-May-13 0:36
mvpAbhinav S2-May-13 0:36 
Questionmodify C# 2008 desktop application Pin
classy_dog1-May-13 17:47
memberclassy_dog1-May-13 17:47 
AnswerRe: modify C# 2008 desktop application Pin
Pete O'Hanlon1-May-13 19:54
protectorPete O'Hanlon1-May-13 19:54 
Questionunexpected end of file Pin
miket2144123451-May-13 14:54
membermiket2144123451-May-13 14:54 
AnswerRe: unexpected end of file Pin
Freak301-May-13 23:26
memberFreak301-May-13 23:26 
AnswerRe: unexpected end of file Pin
Eddy Vluggen2-May-13 1:30
mvpEddy Vluggen2-May-13 1:30 
QuestionProblem while exporting a aspx page to pdf Pin
Member 100216341-May-13 0:20
memberMember 100216341-May-13 0:20 
i have designed a table as shown below. the are two literal controls as i am binding the datatable to the literal contol creating a tabular structre in the page load itself. The data is displayed correctly in default.aspx page. i want to export this aspx page to pdf . I using Itextsharp.dll.

On button click i have written code. The PDF is generated but it is getting distorted. Not getting generated as per the displayed aspx page.

Default.aspx and cs file is pasted below.

<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div width="100%">
    <asp:Panel ID="pnl" runat="server">
    <table style="width:100%; border:1 solid black">
    <tr>
    <td align="center" style="width:100%" colspan="2" >
    Customer Details
    </td>
    </tr>
 
    <tr>
    <td style="width:30%">
    <asp:Literal ID="litvac" runat="server"></asp:Literal>
    </td>
    <td align="center" style="width:30%">
    <asp:literal id="litsal" runat="server"></asp:literal>
    </td>
           </tr>
 
    </table>
    </asp:Panel>
     <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </div>
 
    </form>
</body>
</html>


now the cs file is as below

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string Qexp1 = "select * from emp";
            string dconn = ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString;
 
            OracleConnection oraconn = new OracleConnection(dconn);
            oraconn.Open();
            OracleCommand oracmd = new OracleCommand("select * from emp", oraconn);
            oracmd.CommandType = CommandType.Text;
            DataTable dt = new DataTable();
            OracleDataReader oda = oracmd.ExecuteReader();
            dt.Load(oda);
 

            litvac.Text = "<table cellspacing='0' cellpadding='0' width='50%' border='1'><tr><td colspan='8' class='td_bg' align='Center' style='border-color: #808080'><b>Value Of Account [Fig. are in lacs]</b>";
            litvac.Text += "</td></tr><tr><td align='center' style='border:1 solid #808080'><b>EMP</b></td><td align='center' style='border:1 solid #808080'><b>Ename</b></td></tr>";
            for (int k = 0; k <= dt.Rows.Count - 1; k++)
            {
 

                litvac.Text += "<tr><td align='center' style='border:1 solid #808080'>" + Convert.ToString(dt.Rows[k]["empno"]) + "</td><td align='left' style='border:1 solid #808080'>" + Convert.ToString(dt.Rows[k]["ename"]) + "</td></tr>";
            }
            litvac.Text += "</table>";
 

            litsal.Text = "<table cellspacing='0' cellpadding='0' width='50%' border='1'><tr><td colspan='8' class='td_bg' align='Center' style='border-color: #808080'><b>Value Of Account [Fig. are in lacs]</b>";
            litsal.Text += "</td></tr><tr><td align='center' style='border:1 solid #808080'><b>job</b></td><td align='center' style='border:1 solid #808080'><b>sal</b></td></tr>";
            for (int k = 0; k <= dt.Rows.Count - 1; k++)
            {
 

                litsal.Text += "<tr><td align='center' style='border:1 solid #808080'>" + Convert.ToString(dt.Rows[k]["job"]) + "</td><td align='left' style='border:1 solid #808080'>" + Convert.ToString(dt.Rows[k]["sal"]) + "</td></tr>";
            }
            litsal.Text += "</table>";
 
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        this.Page.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();
 
    }
}

AnswerRe: Problem while exporting a aspx page to pdf Pin
Jasmine25011-May-13 9:40
memberJasmine25011-May-13 9:40 
QuestionBest practice to select and copy a file to a remote location? Pin
matleeds1-May-13 0:07
membermatleeds1-May-13 0:07 
AnswerRe: Best practice to select and copy a file to a remote location? Pin
Jasmine25011-May-13 9:37
memberJasmine25011-May-13 9:37 
AnswerRe: Best practice to select and copy a file to a remote location? Pin
jschell1-May-13 9:41
memberjschell1-May-13 9:41 
Questionpassword creation in c# winform Pin
Member 1002123530-Apr-13 19:39
memberMember 1002123530-Apr-13 19:39 
AnswerRe: password creation in c# winform Pin
Richard MacCutchan30-Apr-13 22:42
mvpRichard MacCutchan30-Apr-13 22:42 
AnswerRe: password creation in c# winform Pin
GuyThiebaut1-May-13 3:14
memberGuyThiebaut1-May-13 3:14 
Questionhow to get the value of a control in a process which start with Process.start Pin
Member 1001614230-Apr-13 19:11
professionalMember 1001614230-Apr-13 19:11 
AnswerRe: how to get the value of a control in a process which start with Process.start Pin
Richard MacCutchan30-Apr-13 22:37
mvpRichard MacCutchan30-Apr-13 22:37 
GeneralRe: how to get the value of a control in a process which start with Process.start Pin
Member 100161421-May-13 15:33
professionalMember 100161421-May-13 15:33 
GeneralRe: how to get the value of a control in a process which start with Process.start Pin
Richard MacCutchan1-May-13 22:02
mvpRichard MacCutchan1-May-13 22:02 
QuestionSaving DrawLine to Image: SOLVED Pin
Member 792126830-Apr-13 4:34
memberMember 792126830-Apr-13 4:34 
AnswerRe: Saving DrawLine to Image Pin
Eddy Vluggen30-Apr-13 5:05
mvpEddy Vluggen30-Apr-13 5:05 
GeneralRe: Saving DrawLine to Image Pin
Member 792126830-Apr-13 6:11
memberMember 792126830-Apr-13 6:11 
AnswerRe: Saving DrawLine to Image Pin
Kenneth Haugland30-Apr-13 5:42
professionalKenneth Haugland30-Apr-13 5:42 
GeneralRe: Saving DrawLine to Image Pin
Member 79212681-May-13 1:46
memberMember 79212681-May-13 1:46 
AnswerRe: Saving DrawLine to Image: SOLVED Pin
Member 79212681-May-13 5:39
memberMember 79212681-May-13 5:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 27 May 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid