Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
1. In my project i develop resume my fetching data from action method to view.
after fetching all data to the view (where i bind my template), i want to download that template with data and design.my all data get's fetched successfully but I'm unable to download PDF.
2. I want to download PDF with all data and design.
3. I install ITextSharp NuGet package and perform different operations but unable to download the pdf as per my requirements.
4. In normal pdf format codes we just able download pdf with data but i want to download same as i see the template.
4.I'm providing Controller code from where i pass data to view and also provide view code.
5.I got an error like "The Document has no page."

What I have tried:

ASP.NET
Controller Code: <pre>public async Task<ActionResult> GetSelectedTemplate(int TempId)
		{
			JobSeeker objJ = new JobSeeker();
			BALJobSeeker objBAL = new BALJobSeeker();
			List<JobSeeker> jobSeekers = new List<JobSeeker>();
			objJ.TemplateId = TempId;
			SqlDataReader dr = await objBAL.TemplateNameDetails(objJ);
			// Retrieve ViewBag data from the first action method
			ViewBag.BasicList = TempData["BasicList"];
			ViewBag.QualificationList = TempData["QualificationList"];
			ViewBag.EmployementList = TempData["EmployementList"];
			ViewBag.ProjectList = TempData["ProjectList"];
			ViewBag.CertificationList = TempData["CertificationList"];
			ViewBag.ObjectiveBag = TempData["ObjectiveBag"];
			ViewBag.SkillsExperienceList = TempData["SkillsExperienceList"];

			if (await dr.ReadAsync())
			{
				string templateName = dr["TemplateName"].ToString();
				if (templateName == "Resume_Template_1")
				{
					return View("GetSelectedTemplate");
				}
				else if (templateName == "Resume_Template_3")
				{
					return View("GetSelectedTemplate2");
				}
				else
				{
					return HttpNotFound();
				}
			}
			return View();
		}

<pre lang="ASP.NET"><pre>[HttpGet]
		public async Task<FileResult> Export(string PdfHtml)
		{
			using (MemoryStream stream = new System.IO.MemoryStream())
			{
				StringReader sr = new StringReader(PdfHtml);
				Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
				PdfWriter writer =PdfWriter.GetInstance(pdfDoc, stream);
				pdfDoc.Open();
				XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
				pdfDoc.Close();
				return File(stream.ToArray(), "application/pdf", "TempPdf.pdf");
			}
		}

Just consider only one template
Razor
View Code: 
<pre lang="Razor"><pre>@{
    Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Gaya Templates</title>
    <!-- Meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Responsive Resume Template">
    <meta name="author" content="Xiaoying Riley at 3rd Wave Media">
    <link rel="shortcut icon" href="favicon.ico">
    <!-- Google Font -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900" rel="stylesheet">
    <!-- FontAwesome JS-->
    <script defer src="~/Content/JobSeeker/CSS/fontawesome/js/all.min.js"></script>
    <!-- Theme CSS -->
    <link id="theme-style" rel="stylesheet" href="~/Content/JobSeeker/CSS/pillar-1.css">
    <link href="~/Content/JobSeeker/CSS/ResumeDetailsStyle.css" rel="stylesheet" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#btnSubmit").click(function () {
                $("input[name='btnHtml']").val($("#TempPdf").html());
            });
        });
    </script>
</head>
<body>
    @using (Html.BeginForm("Export", "JobSeeker", FormMethod.Get))
    {
        <input type="hidden" name="PdfHtml" />
        <input type="submit" id="btnSubmit" value="Export" />
        <article class="resume-wrapper text-center position-relative">
            <div class="resume-wrapper-inner mx-auto text-start bg-white shadow-lg">
                <header class="resume-header pt-4 pt-md-0">
                    <div class="row">
                        @foreach (var jobSeeker in ViewBag.BasicList)
                        {
                            <div class="col-block col-md-auto resume-picture-holder text-center text-md-start">
                                @{
                                        var photopath = "Content/JobSeeker/Image/";
                                        var imagePath = string.Format("{0}{1}", photopath, jobSeeker.Photo);
                                    }
                                    <img src="@imagePath" alt="Image" />
                            </div>
                            <div class="col">
                                <div class="row p-4 justify-content-center justify-content-md-between">
                                    <div class="primary-info col-auto">
                                        <h1 class="name mt-0 mb-1 text-white text-uppercase text-uppercase">@jobSeeker.FullName</h1>
                                        @*<div class="title mb-3">Full Stack Developer</div>*@
                                        <ul class="list-unstyled">
                                            <li><a class="text-link" href="#">@jobSeeker.MobileNo</a></li>
                                        </ul>
                                    </div><!--//primary-info-->
                                    <div class="secondary-info col-auto mt-2">
                                        <ul class="resume-social list-unstyled">
                                            <li class="mb-3"><a class="text-link" href="#">^__i class="fab fa-linkedin-in fa-fw">@jobSeeker.ProfileUrl</a></li>
                                            <li class="mb-3"><a class="text-link" href="#">^__i class="fas fa-user fa-fw">@jobSeeker.Gender</a></li>
                                            <li><a class="text-link" href="#">^__i class="fas fa-globe">yourwebsite.com</a></li>
                                        </ul>
                                    </div><!--//secondary-info-->
                                </div><!--//row-->

                            </div><!--//col-->
                        }
                    </div><!--//row-->

                </header>
                <div class="resume-body p-5">
                    <section class="resume-section summary-section mb-5">
                        <h2 class="resume-section-title text-uppercase font-weight-bold pb-3 mb-3">Career Summary</h2>
                        <div class="resume-section-content">
                            <p class="mb-0"> @ViewBag.ObjectiveBag<a class="text-reset text-link" href="https://themes.3rdwavemedia.com/resources/sketch-template/pillar-sketch-sketch-resume-template-for-developers/" target="_blank"></a></p>
                        </div>
                    </section><!--//summary-section-->
                    <div class="row">
                        @foreach (var jobSeeker in ViewBag.EmployementList)
                        {
                            <div class="col-lg-9">
                                <section class="resume-section experience-section mb-5">
                                    <h2 class="resume-section-title text-uppercase font-weight-bold pb-3 mb-3">Work Experience</h2>
                                    <div class="resume-section-content">
                                        <div class="resume-timeline position-relative">
                                            <article class="resume-timeline-item position-relative pb-5">
                                                <div class="resume-timeline-item-header mb-2">
                                                    <div class="d-flex flex-column flex-md-row">
                                                        <h3 class="resume-position-title font-weight-bold mb-1">@jobSeeker.Designation</h3>
                                                        <div class="resume-company-name ms-auto">@jobSeeker.OrganizationName</div>
                                                    </div><!--//row-->
                                                    <div class="resume-position-time">@jobSeeker.StartDate - @jobSeeker.EndDate</div>
                                                </div><!--//resume-timeline-item-header-->
                                                <div class="resume-timeline-item-desc">
                                                    <p>@jobSeeker.JobResponsibilities</p>
                                                    <h4 class="resume-timeline-item-desc-heading font-weight-bold">Total Experience:</h4>
                                                    <p>@jobSeeker.TotalExperience</p>
                                                    <h4 class="resume-timeline-item-desc-heading font-weight-bold">Technologies used:</h4>
                                                    <ul class="list-inline">
                                                        <li class="list-inline-item">
                                                            
                                                                @foreach (var skill in jobSeeker.Skills.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                                                                {
                                                                    @skill.Trim();
                                                                }
                                                            
                                                        </li>
                                                    </ul>
                                                </div><!--//resume-timeline-item-desc-->
                                            </article><!--//resume-timeline-item-->
                                        </div><!--//resume-timeline-->
                                    </div>
                                </section><!--//experience-section-->
                                <section class="resume-section experience-section mb-5">
                                    <h2 class="resume-section-title text-uppercase font-weight-bold pb-3 mb-3">Projects </h2>
                                  
</body>
</html>
Posted
Updated 21-Apr-24 20:56pm
v5
Comments
Dave Kreskowiak 18-Apr-24 20:06pm    
There is no code in what you posted that generates a PDF at all, so there's really nothing to return.
Shubham Sawant 2023 22-Apr-24 2:53am    
I updated my code please check!
Dave Kreskowiak 22-Apr-24 10:09am    
Huh. I came to find out ITextSharp has been end-of-life for quite a while now. Its replacement is iText, which has its own PdfHtml converter in it, and is found here[^].

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