Пример #1
0
        /// <summary>
        /// The method generates a sample pdf-file
        /// </summary>
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Document document = db.GetDocumentById(id);

            if (document == null)
            {
                return(HttpNotFound());
            }
            string correctHtml = document.Text;
            string htm         = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/><title>Контракт</title></head><body>" + document.Text + "</body></html>";
            ///
            string       pattern = @"{{(?<val>.*?)}}";
            RegexOptions options = RegexOptions.Compiled | RegexOptions.Singleline;
            Regex        regex   = new Regex(pattern, options);
            Match        match   = regex.Match(htm);
            int          i       = 0;

            while (match.Success)
            {
                correctHtml = correctHtml.Replace("{{" + match.Groups["val"].Value + "}}", "______");
                match       = match.NextMatch();
                i++;
            }
            ///
            var htmlToPdf = new HtmlToPdfConverter();
            var pdfBytes  = htmlToPdf.GeneratePdf(correctHtml);

            return(File(pdfBytes, "application/pdf", "df"));
        }
Пример #2
0
 public ActionResult FillPage(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     Models.Document doc = db.GetDocumentById(id);
     ViewBag.EmptyFields = doc.Tags.ToList();
     ViewBag.Fields      = doc.Tags.ToList();
     if (doc == null)
     {
         return(HttpNotFound());
     }
     return(View(doc));
 }