Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public void Btn_Click()
{
    var configuration = new ReportConfiguration();
    configuration.PageOrientation = PageSize.LETTER_LANDSCAPE.Rotate();
    configuration.ReportTitle = "Technical reports/certificates";

    string printPOHTML;
    //printPOHTML = "<!DOCTYPE html>";
    printPOHTML = "<html><head><title></title></head><body>";
    printPOHTML = printPOHTML + "<header>Technical reports/certificates</header><h4>The supplier is required to fill out this form and shipped with each individual part:</h4>";
    printPOHTML = printPOHTML + " <table cellspacing="\"0\" rules="\"all\" border="\"1\" style="\"width:100%;border-collapse:collapse;border-color:" mode="hold" />
    printPOHTML = printPOHTML + "<tbody>";
    printPOHTML = printPOHTML + "<tr style="\"white-space:nowrap;\">";
    printPOHTML = printPOHTML + "<th style="\"background-color:gray\" width="\"30%\"> Supplier </th>";
    printPOHTML = printPOHTML + "<td colspan="\"2\" width="\"70%\"> Data of Supplier </td>";
    printPOHTML = printPOHTML + "</tr>";
    printPOHTML = printPOHTML + "<tr style="\"white-space:nowrap;\">";
    printPOHTML = printPOHTML + "<th style="\"background-color:gray\" width="\"30%\"> Date of test </th>";
    printPOHTML = printPOHTML + "<td colspan="\"2\" width="\"70%\"> Data of Date of test </td>";
    printPOHTML = printPOHTML + "</tr>";
    printPOHTML = printPOHTML + "<tr style="\"white-space:nowrap;\">";
    printPOHTML = printPOHTML + "<th style="\"background-color:gray\" width="\"30%\"> Serial # </th>";
    printPOHTML = printPOHTML + "<td colspan="\"2\" width="\"70%\"> Data of Serial # </td>";
    printPOHTML = printPOHTML + "</tr>";
    printPOHTML = printPOHTML + "</tbody>";
    printPOHTML = printPOHTML + "";
    printPOHTML = printPOHTML + "<br /><br />";
    printPOHTML = printPOHTML + "<h5>Note – Supplier should either provide the measurement data or check when the measurement is done and stored.</h5>";
    printPOHTML = printPOHTML + "<table cellspacing="\"0\" rules="\"all\" border="\"1\" style="\"width:100%;border-collapse:collapse;border-color:" mode="hold" />            printPOHTML = printPOHTML + "<tr>";
    printPOHTML = printPOHTML + "<th style="\"background-color:yellow\">Category</th> ";
    printPOHTML = printPOHTML + "<th style="\"background-color:yellow\">12NC</th>";
    printPOHTML = printPOHTML + "<th style="\"background-color:yellow\">Item</th>";
    printPOHTML = printPOHTML + "<th style="\"background-color:yellow\">Spec. Value</th>";
    printPOHTML = printPOHTML + "<th style="\"background-color:yellow\">Meas. Value</th>";
    printPOHTML = printPOHTML + "<th style="\"background-color:yellow\">Chk/Data Stored</th>";
    printPOHTML = printPOHTML + "</tr>";
    // printPOHTML = printPOHTML + "<br /> <br />";
    //foreach code to be written for td
    ///Html code for Footer.
    string footerHtml;
    footerHtml = "<footer>";
    footerHtml = footerHtml + " <table cellspacing="\"0\" rules="\"all\" border="\"1\" style="\"width:100%;border-collapse:collapse;border-color:" mode="hold" />            footerHtml = footerHtml + "<tr>";
    footerHtml = footerHtml + "<td> ASML</td>";
    footerHtml = footerHtml + "<td colspan="\"2\">YS350E OM FOC REF BS PLATE</td>";
    footerHtml = footerHtml + "<td colspan="\"2\"> 4022.656.1758</td>";
    footerHtml = footerHtml + "<td colspan="\"2\">";
    footerHtml = footerHtml + "<table border="\"1\" style="\"width:" mode="hold" />            footerHtml = footerHtml + "<tr><td>1</td></tr>";
    footerHtml = footerHtml + "<tr><td>2</td></tr>";
    footerHtml = footerHtml + "<tr><td>3</td></tr>";
    footerHtml = footerHtml + "<tr><td>4</td></tr>";
    footerHtml = footerHtml + "<tr><td>5</td></tr>";
    footerHtml = footerHtml + "";
    footerHtml = footerHtml + "</td>";
    footerHtml = footerHtml + "</tr>";
    footerHtml = footerHtml + "<tr>";
    footerHtml = footerHtml + "<td colspan="\"2\">Name</td>";
    footerHtml = footerHtml + "<td>FORMER 12NC:</td>";
    footerHtml = footerHtml + "<td>SHEET:</td>";
    footerHtml = footerHtml + "<td>SHEETS:</td>";
    footerHtml = footerHtml + "<td>SYS:</td>";
    footerHtml = footerHtml + "<td>SIZE:</td>";
    footerHtml = footerHtml + "</tr>";
    footerHtml = footerHtml + "<td>CHECKED BY:</td>";
    footerHtml = footerHtml + "<td>STATUS:</td>";
    footerHtml = footerHtml + " <td colspan="\"2\">NAME CODEVELOPER:</td>";
    footerHtml = footerHtml + "<td colspan="\"3\">SHEET:</td>";
    footerHtml = footerHtml + "";
    footerHtml = footerHtml + "";
    footerHtml = footerHtml + "</footer></body></html>";

    string htmlText = printPOHTML + footerHtml;


    Response.Clear();
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=Student Details.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.BinaryWrite(stream.ToArray());
}
Posted
Updated 15-Jan-16 4:21am
v3
Comments
Richard Deeming 15-Jan-16 10:24am    
I've fixed the formatting of your code. However, it looks like some of your code was missing - the code you've posted will not compile, and there is no mention of iTextSharp in your code.
.net bigner 18-Jan-16 1:00am    
ya i have to write Response.BinaryWrite(htmlText); in last line.
But it is a wrong formating of Response.BinaryWrite().
Richard Deeming 18-Jan-16 7:14am    
No.

If you want to write a string to the response, you need to use Response.Write.

But you've specified that the content type is application/pdf. You cannot just write an HTML string to the response, tell the browser it's a PDF, and expect it to work.

You need to use iTextSharp to convert your HTML to a real PDF before you send it back to the browser. Google has plenty of examples of how to do that.

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