public ActionResult Index(PrescricaoDataModel model)
        {
            // Guarantees that the "App_Data" folder exists.
            if (!Directory.Exists(StorageMock.AppDataPath))
            {
                Directory.CreateDirectory(StorageMock.AppDataPath);
            }
            var filename = Guid.NewGuid() + ".pdf";
            var userFile = Path.Combine(StorageMock.AppDataPath, filename);

            using (var stream = new FileStream(userFile, FileMode.OpenOrCreate)) {
                // PdfGeneration.ReceitaSimples(), to see how the custom sample pdf is generated.
                var content = PdfGeneration.ReceitaSimples(model.Name, model.Crm, model.CrmUf);

                var reader  = new PdfReader(content);
                var stamper = new PdfStamper(reader, stream);

                // REQUIRED!!!
                // Add all the required receita simples metadata,
                // when value is not specified it uses empty strings.
                var infos = new Hashtable
                {
                    { DocumentType.PrescricaoMedicamento.GetValue(), "Prescrição de medicamento" },
                    { FieldName.Crm.GetValue(), model.Crm },
                    { FieldName.CrmUF.GetValue(), model.CrmUf },
                    { FieldName.CrmEspecialidade.GetValue(), "" },
                    { FieldName.Crf.GetValue(), "" },
                    { FieldName.CrfUF.GetValue(), "" },
                    { FieldName.CrfEspecialidade.GetValue(), "" }
                };

                // Add metadata to pdf
                stamper.MoreInfo = infos;
                stamper.Close();
                reader.Close();
            }
            return(RedirectToAction("Start", new SignatureStartModel()
            {
                UserFile = filename.Replace(".", "_")
            }));
        }
        public ActionResult Index(PrescricaoDataModel model)
        {
            // Guarantees that the "App_Data" folder exists.
            if (!Directory.Exists(StorageMock.AppDataPath))
            {
                Directory.CreateDirectory(StorageMock.AppDataPath);
            }
            var filename = Guid.NewGuid() + ".pdf";
            var userFile = Path.Combine(StorageMock.AppDataPath, filename);

            using (var stream = new FileStream(userFile, FileMode.OpenOrCreate)) {
                var document = new Document();
                var writer   = PdfWriter.GetInstance(document, stream);
                document.Open();

                // Add title.
                var title = new Paragraph("RECEITUÁRIO SIMPLES", new Font(null, 20f, Font.BOLD))
                {
                    Alignment = Element.ALIGN_CENTER,
                };
                document.Add(title);

                var table = new PdfPTable(6);
                table.WidthPercentage = 100;

                // Field "Tipo de Documento". This text field identifies the type of
                // document is being generated. It's a hidden field because this type
                // is identified by the field name and NOT by the value of this field.
                var tipoField = new PdfPCell()
                {
                    Colspan = 6,
                    Border  = Rectangle.NO_BORDER,
                };
                tipoField.CellEvent = new TextFieldCellWrapper()
                {
                    // See Enums.cs, to see what is the value of this enum below.
                    FieldName = DocumentType.PrescricaoMedicamento.GetValue(),
                    Value     = string.Empty,
                    ReadOnly  = true,
                    Hidden    = true,
                };
                table.AddCell(tipoField);

                // Fields with default values
                for (int i = 0; i < DefaultFieldName.Length; i++)
                {
                    var fieldLabel = new PdfPCell()
                    {
                        Colspan = 2,
                        Border  = Rectangle.NO_BORDER,
                    };
                    fieldLabel.AddElement(new Phrase(DefaultFieldLabel[i]));
                    table.AddCell(fieldLabel);
                    var valueField = new PdfPCell()
                    {
                        Colspan = 4,
                        Border  = Rectangle.NO_BORDER,
                    };
                    valueField.CellEvent = new TextFieldCellWrapper()
                    {
                        FieldName = DefaultFieldName[i],
                        Value     = DefaultFieldValues[i],
                        ReadOnly  = true,
                    };
                    table.AddCell(valueField);
                }

                // Field "Nome do(a) Médico(a)".
                var doctorNameLabel = new PdfPCell()
                {
                    Colspan = 2,
                    Border  = Rectangle.NO_BORDER,
                };
                doctorNameLabel.AddElement(new Phrase("NOME DO(A) MÉDICO(A):"));
                table.AddCell(doctorNameLabel);
                var doctorNameField = new PdfPCell()
                {
                    Colspan = 4,
                    Border  = Rectangle.NO_BORDER,
                };
                doctorNameField.CellEvent = new TextFieldCellWrapper()
                {
                    FieldName = "03_Nome Completo Emitente",
                    Value     = model.Name,
                    ReadOnly  = true,
                };
                table.AddCell(doctorNameField);

                // Field "CRM". This text field contains the doctor's register
                // number on CRM.
                var crmLabel = new PdfPCell()
                {
                    Colspan = 2,
                    Border  = Rectangle.NO_BORDER,
                };
                crmLabel.AddElement(new Phrase("CRM:"));
                table.AddCell(crmLabel);
                var crmField = new PdfPCell()
                {
                    Colspan = 4,
                    Border  = Rectangle.NO_BORDER,
                };
                crmField.CellEvent = new TextFieldCellWrapper()
                {
                    // See Enums.cs, to see what is the value of this enum below.
                    FieldName = FieldName.Crm.GetValue(),
                    Value     = model.Crm,
                    ReadOnly  = true,
                };
                table.AddCell(crmField);

                // Field "CRM UF". This combo box field contains the "UF" where the
                // doctor is registered.
                var crmUFLabel = new PdfPCell()
                {
                    Colspan = 2,
                    Border  = Rectangle.NO_BORDER,
                };
                crmUFLabel.AddElement(new Phrase("CRM UF:"));
                table.AddCell(crmUFLabel);
                var crmUFField = new PdfPCell()
                {
                    Colspan = 4,
                    Border  = Rectangle.NO_BORDER,
                };
                crmUFField.CellEvent = new ComboFieldCellWrapper()
                {
                    // See Enums.cs, to see what is the value of this enum below.
                    FieldName = FieldName.CrmUF.GetValue(),
                    Options   = ufs,
                    Selection = model.CrmUf,
                    ReadOnly  = true,
                };
                table.AddCell(crmUFField);

                // Add table.
                document.Add(table);

                document.Close();
                writer.Close();
            }
            return(RedirectToAction("Start", new SignatureStartModel()
            {
                UserFile = filename.Replace(".", "_")
            }));
        }