Click here to Skip to main content
15,882,114 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
This Is My cshtml Code

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Apply For Pdf</title>
    @*<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.debug.js"></script>*@
</head>
<body>
    <table class="table table-bordered border-secondary" id="tab" style="margin-top: 15rem;">
        <tr>
            <th class="text-center">Id</th>
            <th class="text-center">Name</th>
            <th class="text-center">Phone</th>
            <th class="text-center">Address</th>
        </tr>

        <tr class="text-center">
            <td>1</td>
            <td>Tushar Paul</td>
            <td>8167580245</td>
            <td>Coochbehar</td>
        </tr>

        <tr class="text-center">
            <td>2</td>
            <td>Anirban Panja</td>
            <td>7896541236</td>
            <td>Alipurduar</td>
        </tr>

        <tr class="text-center">
            <td>3</td>
            <td>Koushik Saha</td>
            <td>7699925135</td>
            <td>Coochbehar</td>
        </tr>

        <tr class="text-center">
            <td>4</td>
            <td>Sourav Das</td>
            <td>9874563258</td>
            <td>Tufanganj</td>
        </tr>

        <tr class="text-center">
            <td>5</td>
            <td>Sharmistha Deb</td>
            <td>7893214569</td>
            <td>New Coochbehar</td>
        </tr>

        <tr class="text-center">
            <td>6</td>
            <td>Subhradeep Ch.</td>
            <td>7896325412</td>
            <td>Jalpaiguri</td>
        </tr>
    </table>


And This Is My C# Code

public ActionResult ApplyForPdf()
       {
           Document doc = new Document(PageSize.A4, 0f, 0f, 0f, 0f);
           doc.SetPageSize(PageSize.A4);
           doc.SetMargins(20f, 20f, 20f, 20f);
           byte[] pdfBytes;
           var mem = new MemoryStream();
           pdfBytes = mem.ToArray();
           return File(pdfBytes, "application/pdf");
           //return View();
       }


What I have tried:

public ActionResult ApplyForPdf()
       {
           Document doc = new Document(PageSize.A4, 0f, 0f, 0f, 0f);
           doc.SetPageSize(PageSize.A4);
           doc.SetMargins(20f, 20f, 20f, 20f);
           byte[] pdfBytes;
           var mem = new MemoryStream();
           pdfBytes = mem.ToArray();
           return File(pdfBytes, "application/pdf");
           //return View();
       }

----------------------------------------------------------------------

using (var mem = new MemoryStream())
            {
                Document doc = new Document(PageSize.A4, 0f, 0f, 0f, 0f);               
                doc.SetPageSize(PageSize.A4);                
                return File(mem.ToArray(), "application/pdf", "Apply For Pdf.pdf");
            }

------------------------------------------------------------------

Document pdfDoc = new Document(PageSize.A4, 25, 25, 25, 15);
           PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
           pdfWriter.CloseStream = false;
           Response.Buffer = true;
           Response.ContentType = "application/pdf";
           Response.AddHeader("content-disposition", "attachment;filename = Apply For Pdf.pdf");
           Response.Cache.SetCacheability(HttpCacheability.NoCache);
           Response.Write(pdfDoc);
           Response.End();
           return View(pdfDoc);

--------------------------------------------------------------------

All Of This Code I Tried Tnto The Same ActionResult...
Posted

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