Пример #1
0
        public float AddRadioGroup(ItemRef item, Rectangle rectStart, List <String> labels, int distance)
        {
            int fieldFlags = 0;

            float curY = rectStart.Top;

            drawingFuncs.Add(() =>
            {
                PdfFormField group = PdfFormField.CreateRadioButton(writer, true);
                group.FieldName    = item.UniqueId;
                for (int i = 0; i < labels.Count; i++)
                {
                    Rectangle rect     = new Rectangle(rectStart.Left + i * distance, rectStart.Top, rectStart.Right + i * distance, rectStart.Bottom);
                    RadioCheckField tf = new RadioCheckField(Writer, rect, item.UniqueId + "_" + i.ToString(), i.ToString())
                    {
                        BackgroundColor = new GrayColor(0.8f),
                        BorderColor     = GrayColor.BLACK,
                        CheckType       = RadioCheckField.TYPE_CIRCLE,
                        BorderStyle     = PdfBorderDictionary.STYLE_SOLID,
                        FontSize        = 12
                    };
                    group.AddKid(tf.RadioField);
                }
                if (item.IsMandatory)
                {
                    fieldFlags = fieldFlags | PdfFormField.FF_REQUIRED;
                }
                group.SetFieldFlags(fieldFlags);
                stamper.AddAnnotation(group, 1);
            });
            return(curY);
        }
        public static byte[] GetPdf()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (Document document = new Document())
                {
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    document.Open();

                    int i = 0;
                    foreach (var fieldName in FieldNames)
                    {
                        var rectangle = new Rectangle(20, 800 - i * 40, 40, 780 - i * 40);
                        var checkbox  = new RadioCheckField(
                            writer, rectangle, fieldName, ON_STATE
                            );
                        checkbox.CheckType = RadioCheckField.TYPE_CHECK;
                        PdfFormField field = checkbox.CheckField;
                        writer.AddAnnotation(field);
                        ++i;
                    }

                    // add textbox field for sanity-check
                    var textField = new TextField(
                        writer,
                        new Rectangle(20, 800 - i * 40, 400, 780 - i * 40),
                        TEXT_FIELD
                        );
                    writer.AddAnnotation(textField.GetTextField());
                }
                return(ms.ToArray());
            }
        }
Пример #3
0
        private void CreateOutput(string PDFInput)
        {
            try
            {
                iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(@PDFInput);
                FileStream fs    = new FileStream(@PDFInput.Replace("Input", "Output"), FileMode.Create, FileAccess.Write);
                PdfStamper stamp = new PdfStamper(reader, fs);
                //Loop from here

                //MessageBox.Show(dataGridView1.RowCount.ToString());
                for (int i = 0; i < dataGridView1.RowCount - 1; i++)
                {
                    string comptype = dataGridView1.Rows[i].Cells[3].Value.ToString();

                    string complocation = dataGridView1.Rows[i].Cells[1].Value.ToString();

                    float llx = float.Parse(complocation.Split(' ')[0]);
                    float lly = float.Parse(complocation.Split(' ')[1]);
                    float urx = float.Parse(complocation.Split(' ')[2]);
                    float ury = float.Parse(complocation.Split(' ')[3]);


                    if (comptype == "TE")
                    {
                        int          x  = Int32.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
                        PdfFormField ff = PdfFormField.CreateTextField(stamp.Writer, false, false, 50);
                        ff.SetWidget(new iTextSharp.text.Rectangle(llx, lly, urx, ury), PdfAnnotation.HIGHLIGHT_INVERT);
                        ff.SetFieldFlags(PdfAnnotation.FLAGS_PRINT);
                        ff.FieldName = dataGridView1.Rows[i].Cells[0].Value.ToString();
                        stamp.AddAnnotation(ff, x);
                    }
                    else if (comptype == "CB")
                    {
                        int             x     = Int32.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
                        RadioCheckField fCell = new RadioCheckField(stamp.Writer, new iTextSharp.text.Rectangle(llx, lly, urx, ury), dataGridView1.Rows[i].Cells[0].Value.ToString(), "Yes");
                        fCell.CheckType = RadioCheckField.TYPE_CROSS;
                        PdfFormField footerCheck = null;
                        footerCheck = fCell.CheckField;
                        stamp.AddAnnotation(footerCheck, x);
                    }
                    else
                    {
                    }
                }
                //Loop Ends here

                stamp.Close();
                fs.Close();
                reader.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #4
0
        /// <summary>
        /// METODO 3: Sostituire un acrofield di tipo signature con un acrofield di tipo checkbox
        /// Locking for a checkbox and checking it
        /// </summary>
        /// <param name="fieldName">string Name of the signaturefield to substitute</param>
        public void SubstituteSignature(string fieldName)
        {
            //Checking if argument is null
            if (fieldName == null)
            {
                throw new ArgumentNullException(fieldName);
            }

            //Getting fields
            AcroFields form = reader.AcroFields;

            //Checking if document has no fields
            if (form.Fields.Count == 0)
            {
                throw new DocumentHasNoFieldsException();
            }

            //Looking for a signatureBox with the given name
            var result = form.Fields
                         .Where(kvp =>
                                form.GetTranslatedFieldName(kvp.Key).Equals(fieldName) &&
                                form.GetFieldType(kvp.Key) == AcroFields.FIELD_TYPE_SIGNATURE
                                )
                         .Select(kvp => new { kvp.Key, Position = form.GetFieldPositions(kvp.Key) })
                         ?.FirstOrDefault();

            //Checking if the query had results
            if (result == null)
            {
                throw new FieldNotFoundException(fieldName, AcroFields.FIELD_TYPE_SIGNATURE);
            }

            //Removing field
            form.RemoveField(result.Key);

            //Creating new checkbox with signaturefield's coordinates
            //Note: We're replacing the first occurrence
            RadioCheckField checkbox = new RadioCheckField(stamper.Writer, result.Position[0].position, "i_was_a_signature_field", "Yes")
            {
                //Setting look
                CheckType       = RadioCheckField.TYPE_CHECK,
                Checked         = true,
                BorderWidth     = BaseField.BORDER_WIDTH_THIN,
                BorderColor     = BaseColor.BLACK,
                BackgroundColor = BaseColor.WHITE
            };

            //Adding checbox in signaturefield's page
            stamper.AddAnnotation(checkbox.CheckField, result.Position[0].page);
        }
        public void Verify_RadioButtons_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document();

            // step 2
            var writer = PdfWriter.GetInstance(document, stream);

            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            var cb = writer.DirectContent;
            var bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);

            var radiogroup = PdfFormField.CreateRadioButton(writer, true);

            radiogroup.FieldName = "language";
            var rect = new Rectangle(40, 806, 60, 788);

            for (var page = 0; page < _languages.Length;)
            {
                var radio = new RadioCheckField(writer, rect, null, _languages[page])
                {
                    BackgroundColor = new GrayColor(0.8f)
                };
                var radiofield = radio.RadioField;
                radiofield.PlaceInPage = ++page;
                radiogroup.AddKid(radiofield);
            }
            writer.AddAnnotation(radiogroup);
            foreach (string lang in _languages)
            {
                cb.BeginText();
                cb.SetFontAndSize(bf, 18);
                cb.ShowTextAligned(Element.ALIGN_LEFT, lang, 70, 790, 0);
                cb.EndText();
                document.NewPage();
            }

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
Пример #6
0
// ---------------------------------------------------------------------------

        /**
         * Creates a PDF document.
         */
        public byte[] CreatePdf()
        {
            using (MemoryStream ms = new MemoryStream()) {
                using (Document document = new Document()) {
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    document.Open();

                    BaseFont       bf            = BaseFont.CreateFont();
                    PdfContentByte directcontent = writer.DirectContent;
                    directcontent.BeginText();
                    directcontent.SetFontAndSize(bf, 12);
                    directcontent.ShowTextAligned(Element.ALIGN_LEFT, "Married?", 36, 770, 0);
                    directcontent.ShowTextAligned(Element.ALIGN_LEFT, "YES", 58, 750, 0);
                    directcontent.ShowTextAligned(Element.ALIGN_LEFT, "NO", 102, 750, 0);
                    directcontent.ShowTextAligned(
                        Element.ALIGN_LEFT, "Name partner?", 36, 730, 0
                        );
                    directcontent.EndText();

                    PdfFormField married = PdfFormField.CreateRadioButton(writer, true);
                    married.FieldName   = "married";
                    married.ValueAsName = "yes";
                    Rectangle       rectYes = new Rectangle(40, 766, 56, 744);
                    RadioCheckField yes     = new RadioCheckField(writer, rectYes, null, "yes");
                    yes.Checked = true;
                    married.AddKid(yes.RadioField);
                    Rectangle       rectNo = new Rectangle(84, 766, 100, 744);
                    RadioCheckField no     = new RadioCheckField(writer, rectNo, null, "no");
                    no.Checked = false;
                    married.AddKid(no.RadioField);
                    writer.AddAnnotation(married);

                    Rectangle rect    = new Rectangle(40, 710, 200, 726);
                    TextField partner = new TextField(writer, rect, "partner");
                    partner.BorderColor = GrayColor.GRAYBLACK;
                    partner.BorderWidth = 0.5f;
                    writer.AddAnnotation(partner.GetTextField());
                }
                return(ms.ToArray());
            }
        }
        public void AddFields()
        {
            PdfContentByte cb          = writer.DirectContent;
            Font           _bf         = new Font(Font.FontFamily.HELVETICA, 9);
            PdfFormField   _radioGroup = PdfFormField.CreateRadioButton(writer, true);

            _radioGroup.FieldName   = "language_gc";
            _radioGroup.PlaceInPage = 0;
            Rectangle       _rect;
            RadioCheckField _radioG;
            PdfFormField    _radioField1;

            for (int i = 0; i < LANGUAGES_gc.Length; i++)
            {
                _rect   = new Rectangle(40, 806 - i * 40, 60, 788 - i * 40);
                _radioG = new RadioCheckField(writer, _rect, null, LANGUAGES_gc[i])
                {
                    BackgroundColor = new GrayColor(0.8f),
                    BorderColor     = GrayColor.BLACK,
                    CheckType       = RadioCheckField.TYPE_CIRCLE
                };
                _radioField1 = _radioG.RadioField;
                _radioGroup.AddKid(_radioField1);
                ColumnText.ShowTextAligned(cb, Element.ALIGN_LEFT, new Phrase(LANGUAGES_gc[i], new Font(Font.FontFamily.HELVETICA, 18)), 70, 790 - i * 40, 0);
            }
            writer.AddAnnotation(_radioGroup);
            cb = writer.DirectContent;

            TextField _text = new TextField(writer, new Rectangle(ConvertX(103), ConvertY(190), ConvertX(182), ConvertY(199)), "g1");

            _text.Alignment = Element.ALIGN_CENTER;
            _text.Options   = TextField.MULTILINE;
            _text.Text      = "abc";
            PdfFormField textbox = _text.GetTextField();

            textbox.PlaceInPage = 1;
            writer.AddAnnotation(textbox);
            cb = writer.DirectContentUnder;
            table.WriteSelectedRows(0, -1, ConvertX(25), ConvertY(133), cb);
            idTable.WriteSelectedRows(0, -1, ConvertX(25), ConvertY(205), cb);
        }
Пример #8
0
// ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                PdfContentByte cb = writer.DirectContent;
                BaseFont       bf = BaseFont.CreateFont(
                    BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED
                    );

                PdfFormField radiogroup = PdfFormField.CreateRadioButton(
                    writer, true
                    );
                radiogroup.FieldName = "language";
                Rectangle       rect = new Rectangle(40, 806, 60, 788);
                RadioCheckField radio;
                PdfFormField    radiofield;
                for (int page = 0; page < LANGUAGES.Length;)
                {
                    radio = new RadioCheckField(writer, rect, null, LANGUAGES[page]);
                    radio.BackgroundColor  = new GrayColor(0.8f);
                    radiofield             = radio.RadioField;
                    radiofield.PlaceInPage = ++page;
                    radiogroup.AddKid(radiofield);
                }
                writer.AddAnnotation(radiogroup);
                for (int i = 0; i < LANGUAGES.Length; i++)
                {
                    cb.BeginText();
                    cb.SetFontAndSize(bf, 18);
                    cb.ShowTextAligned(Element.ALIGN_LEFT, LANGUAGES[i], 70, 790, 0);
                    cb.EndText();
                    document.NewPage();
                }
            }
        }
        public MemoryStream GeneratePdfTemplate(VBRealizationPdfDto viewModel, int timeoffsset)
        {
            const int MARGIN          = 20;
            const int MARGIN_VERTICAL = 10;

            Font header_font      = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18);
            Font normal_font      = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11);
            Font normal_font_8    = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9);
            Font bold_font        = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11);
            Font bold_font_8      = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            Font note_font        = FontFactory.GetFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            Font bold_italic_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12);
            Font Title_bold_font  = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 13);

            Document     document = new Document(PageSize.A4, MARGIN_VERTICAL, MARGIN_VERTICAL, MARGIN, MARGIN);
            MemoryStream stream   = new MemoryStream();
            PdfWriter    writer   = PdfWriter.GetInstance(document, stream);

            document.Open();

            #region Header
            PdfPTable headerTable_A = new PdfPTable(2);
            PdfPTable headerTable_B = new PdfPTable(1);
            PdfPTable headerTable_C = new PdfPTable(1);
            PdfPTable headerTable1  = new PdfPTable(1);
            PdfPTable headerTable2  = new PdfPTable(1);
            PdfPTable headerTable3  = new PdfPTable(7);
            PdfPTable headerTable3a = new PdfPTable(5);
            PdfPTable headerTable4  = new PdfPTable(2);

            headerTable_A.SetWidths(new float[] { 10f, 10f });
            headerTable_A.WidthPercentage = 100;
            headerTable3.SetWidths(new float[] { 5f, 15f, 15f, 15f, 15f, 15f, 20f });
            headerTable3.WidthPercentage = 110;
            headerTable3a.SetWidths(new float[] { 3f, 15f, 5f, 15f, 62f });
            headerTable3a.WidthPercentage = 110;
            headerTable4.SetWidths(new float[] { 10f, 40f });
            headerTable4.WidthPercentage = 100;

            PdfPCell cellHeader1 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeader2 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeader3 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeader4 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeader3a = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody1 = new PdfPCell()
            {
            };
            PdfPCell cellHeaderBody1a = new PdfPCell()
            {
                BorderWidthTop = 2
            };
            PdfPCell cellHeaderBody1a1 = new PdfPCell()
            {
            };
            PdfPCell cellHeaderBody1a2 = new PdfPCell()
            {
            };
            PdfPCell cellHeaderBody1b = new PdfPCell()
            {
                BorderWidthTop = 2
            };
            PdfPCell cellHeaderBody1b1 = new PdfPCell()
            {
            };
            PdfPCell cellHeaderBody1b2 = new PdfPCell()
            {
            };
            PdfPCell cellHeaderBody1c = new PdfPCell()
            {
            };
            PdfPCell cellHeaderBody2 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody3 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody4 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody4a = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody4b = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody5 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody5a = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody6 = new PdfPCell()
            {
            };

            cellHeader1.AddElement(headerTable1);
            headerTable_A.AddCell(cellHeader1);
            cellHeader2.AddElement(headerTable2);
            headerTable_A.AddCell(cellHeader2);
            document.Add(headerTable_A);

            cellHeaderBody.HorizontalAlignment    = Element.ALIGN_LEFT;
            cellHeaderBody1.HorizontalAlignment   = Element.ALIGN_CENTER;
            cellHeaderBody1a.HorizontalAlignment  = Element.ALIGN_CENTER;
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_CENTER;
            cellHeaderBody1a2.HorizontalAlignment = Element.ALIGN_CENTER;
            cellHeaderBody1b.HorizontalAlignment  = Element.ALIGN_CENTER;
            cellHeaderBody1b1.HorizontalAlignment = Element.ALIGN_CENTER;
            cellHeaderBody1b2.HorizontalAlignment = Element.ALIGN_CENTER;
            cellHeaderBody1c.HorizontalAlignment  = Element.ALIGN_CENTER;
            cellHeaderBody2.HorizontalAlignment   = Element.ALIGN_CENTER;
            cellHeaderBody3.HorizontalAlignment   = Element.ALIGN_LEFT;
            cellHeaderBody4.HorizontalAlignment   = Element.ALIGN_CENTER;
            cellHeaderBody4a.HorizontalAlignment  = Element.ALIGN_CENTER;
            cellHeaderBody4b.HorizontalAlignment  = Element.ALIGN_LEFT;
            cellHeaderBody5.HorizontalAlignment   = Element.ALIGN_RIGHT;
            cellHeaderBody5a.HorizontalAlignment  = Element.ALIGN_CENTER;
            cellHeaderBody6.HorizontalAlignment   = Element.ALIGN_LEFT;

            // Document title
            cellHeaderBody2.Colspan = 7;
            cellHeaderBody2.Phrase  = new Phrase("REALISASI VB DENGAN PO", bold_font);
            headerTable3.AddCell(cellHeaderBody2);

            // Document number
            cellHeaderBody3.Colspan             = 7;
            cellHeaderBody3.HorizontalAlignment = Element.ALIGN_RIGHT;
            cellHeaderBody3.Phrase = new Phrase($"{viewModel.Header.DocumentNo}", bold_font);
            headerTable3.AddCell(cellHeaderBody3);

            // Realisasi VB Bagian
            cellHeaderBody3.Colspan             = 7;
            cellHeaderBody3.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody3.Phrase = new Phrase($"Realisasi VB Bagian: {viewModel.Header.SuppliantUnitName}", bold_font);
            headerTable3.AddCell(cellHeaderBody3);

            // Tanggal
            cellHeaderBody3.Colspan = 7;
            cellHeaderBody3.Phrase  = new Phrase($"Tanggal: {viewModel.Header.Date.AddHours(timeoffsset).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", bold_font);
            headerTable3.AddCell(cellHeaderBody3);

            // New line
            cellHeaderBody3.Phrase = new Phrase(" ", normal_font);
            headerTable3.AddCell(cellHeaderBody3);

            // Table header
            cellHeaderBody1.Phrase = new Phrase("No", normal_font);
            headerTable3.AddCell(cellHeaderBody1);
            cellHeaderBody1.Phrase = new Phrase("Tanggal", normal_font);
            headerTable3.AddCell(cellHeaderBody1);
            cellHeaderBody1.Colspan = 2;
            cellHeaderBody1.Phrase  = new Phrase("Keterangan", normal_font);
            headerTable3.AddCell(cellHeaderBody1);
            cellHeaderBody1.Colspan = 1;
            cellHeaderBody1.Phrase  = new Phrase("Divisi", normal_font);
            headerTable3.AddCell(cellHeaderBody1);
            cellHeaderBody1.Phrase = new Phrase("Mata Uang", normal_font);
            headerTable3.AddCell(cellHeaderBody1);
            cellHeaderBody1.Phrase = new Phrase("Jumlah", normal_font);
            headerTable3.AddCell(cellHeaderBody1);

            int     index             = 1;
            decimal count_price       = 0;
            decimal total_realization = 0;
            decimal total_all         = 0;

            var currencyCode        = viewModel.Header.CurrencyCode;
            var currencydescription = viewModel.Header.CurrencyDescription;

            foreach (var itm in viewModel.Items)
            {
                // No
                cellHeaderBody1.Phrase = new Phrase(index.ToString(), normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER;
                headerTable3.AddCell(cellHeaderBody1);
                index++;

                // Tanggal
                cellHeaderBody1.Phrase = new Phrase(itm.Date.AddHours(timeoffsset).ToString("dd/MM/yyyy"), normal_font);
                headerTable3.AddCell(cellHeaderBody1);

                // Keterangan
                cellHeaderBody1.Colspan             = 2;
                cellHeaderBody1.Phrase              = new Phrase(itm.UnitPaymentOrderNo + Environment.NewLine + itm.SupplierName, normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_LEFT;
                headerTable3.AddCell(cellHeaderBody1);

                // Divisi
                cellHeaderBody1.Colspan             = 1;
                cellHeaderBody1.Phrase              = new Phrase(itm.DivisionName, normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER;
                headerTable3.AddCell(cellHeaderBody1);

                if (itm.UseVat)
                {
                    var temp = itm.Amount * 0.1m;
                    total_all = itm.Amount + temp;
                }
                else
                {
                    total_all = itm.Amount;
                }

                // Mata Uang
                cellHeaderBody1.Phrase = new Phrase(currencyCode, normal_font);
                headerTable3.AddCell(cellHeaderBody1);

                // Jumlah
                cellHeaderBody1.Phrase = new Phrase(itm.Amount.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_RIGHT;
                headerTable3.AddCell(cellHeaderBody1);

                count_price       += total_all;
                total_realization += itm.Amount;
            }

            // Jumlah Realisasi
            cellHeaderBody1a.Colspan             = 5;
            cellHeaderBody1a.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody1a.Phrase = new Phrase("Jumlah Realisasi", normal_font);
            headerTable3.AddCell(cellHeaderBody1a);

            // Mata Uang
            cellHeaderBody1b.Phrase = new Phrase(currencyCode, normal_font);
            headerTable3.AddCell(cellHeaderBody1b);

            // Jumlah
            cellHeaderBody1a.Phrase = new Phrase(total_realization.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
            cellHeaderBody1a.HorizontalAlignment = Element.ALIGN_RIGHT;
            headerTable3.AddCell(cellHeaderBody1a);

            // PPn
            cellHeaderBody1a1.Colspan             = 5;
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody1a1.Phrase = new Phrase("PPN", normal_font);
            headerTable3.AddCell(cellHeaderBody1a1);

            // Mata Uang
            cellHeaderBody1b1.Phrase = new Phrase(currencyCode, normal_font);
            headerTable3.AddCell(cellHeaderBody1b1);

            // Jumlah
            cellHeaderBody1a1.Phrase = new Phrase((count_price - total_realization).ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_RIGHT;
            headerTable3.AddCell(cellHeaderBody1a1);

            // PPh ditanggung Dan Liris
            cellHeaderBody1a1.Colspan             = 5;
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody1a1.Phrase = new Phrase("PPh ditanggung Supplier", normal_font);
            headerTable3.AddCell(cellHeaderBody1a1);

            // Mata Uang
            cellHeaderBody1b1.Phrase = new Phrase(currencyCode, normal_font);
            headerTable3.AddCell(cellHeaderBody1b1);

            // Jumlah
            cellHeaderBody1a1.Phrase = new Phrase((GetPPhValue(viewModel)).ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_RIGHT;
            headerTable3.AddCell(cellHeaderBody1a1);

            // PPh ditanggung Supplier
            cellHeaderBody1a1.Colspan             = 5;
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody1a1.Phrase = new Phrase("PPh ditanggung Dan Liris", normal_font);
            headerTable3.AddCell(cellHeaderBody1a1);

            // Mata Uang
            cellHeaderBody1b1.Phrase = new Phrase(currencyCode, normal_font);
            headerTable3.AddCell(cellHeaderBody1b1);

            // Jumlah
            cellHeaderBody1a1.Phrase = new Phrase((GetPPhValueDanliris(viewModel)).ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_RIGHT;
            headerTable3.AddCell(cellHeaderBody1a1);

            // Total Keseluruhan
            cellHeaderBody1a2.Colspan             = 5;
            cellHeaderBody1a2.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody1a2.Phrase = new Phrase("Total", normal_font);
            headerTable3.AddCell(cellHeaderBody1a2);

            // Mata Uang
            cellHeaderBody1b2.Phrase = new Phrase(currencyCode, normal_font);
            headerTable3.AddCell(cellHeaderBody1b2);

            // Jumlah
            var grandTotal = count_price - GetPPhValue(viewModel);
            cellHeaderBody1a2.Phrase = new Phrase(grandTotal.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
            cellHeaderBody1a2.HorizontalAlignment = Element.ALIGN_RIGHT;
            headerTable3.AddCell(cellHeaderBody1a2);

            var vbDate = viewModel.Header.VBRequestDocumentDate?.AddHours(timeoffsset).ToString("dd-MMMM-yy", new CultureInfo("id-ID"));
            if (viewModel.Header.DocumentType == RealizationDocumentType.NonVB)
            {
                if (!string.IsNullOrWhiteSpace(viewModel.Header.VBRequestDocumentNo))
                {
                    vbDate = viewModel.Header.VBRequestDocumentDate?.AddHours(timeoffsset).ToString("dd-MMMM-yy", new CultureInfo("id-ID"));
                }
                else
                {
                    vbDate = "";
                }
            }

            // Tanggal VB
            cellHeaderBody6.Colspan = 3;
            cellHeaderBody6.Phrase  = new Phrase($"Tanggal VB: {vbDate}", normal_font);
            headerTable3.AddCell(cellHeaderBody6);

            // No VB
            cellHeaderBody1.Colspan = 2;
            cellHeaderBody1.Phrase  = new Phrase($"No.VB: {viewModel.Header.VBRequestDocumentNo}", normal_font);
            headerTable3.AddCell(cellHeaderBody1);

            if (viewModel.Header.VBRequestDocumentId == 0)
            {
                // Mata Uang
                cellHeaderBody1.Colspan             = 1;
                cellHeaderBody1.Phrase              = new Phrase(currencyCode, normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER;
                headerTable3.AddCell(cellHeaderBody1);

                // Jumlah
                cellHeaderBody1.Colspan             = 1;
                cellHeaderBody1.Phrase              = new Phrase(0.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_RIGHT;
                headerTable3.AddCell(cellHeaderBody1);
            }
            else
            {
                // Mata Uang
                cellHeaderBody1.Colspan             = 1;
                cellHeaderBody1.Phrase              = new Phrase(currencyCode, normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER;
                headerTable3.AddCell(cellHeaderBody1);

                // Jumlah
                cellHeaderBody1.Colspan             = 1;
                cellHeaderBody1.Phrase              = new Phrase(viewModel.Header.VBRequestDocumentAmount.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_RIGHT;
                headerTable3.AddCell(cellHeaderBody1);
            }

            var priceterbilang = count_price;
            var res            = (count_price - GetPPhValue(viewModel)) - (viewModel.Header.VBRequestDocumentId == 0 ? 0 : viewModel.Header.VBRequestDocumentAmount);

            if (res > 0)
            {
                // Kurang
                cellHeaderBody5.Colspan = 5;
                cellHeaderBody5.Phrase  = new Phrase("Kurang", bold_font);
                headerTable3.AddCell(cellHeaderBody5);

                // Mata Uang
                cellHeaderBody5a.Phrase = new Phrase(currencyCode, normal_font);
                headerTable3.AddCell(cellHeaderBody5a);

                // Jumlah
                cellHeaderBody5a.Phrase = new Phrase(res.ToString("#,##0.00", new CultureInfo("id-ID")) + ")", normal_font);
                cellHeaderBody5a.HorizontalAlignment = Element.ALIGN_RIGHT; // Override default to center
                headerTable3.AddCell(cellHeaderBody5a);
            }
            else
            {
                // Sisa
                cellHeaderBody5.Colspan = 5;
                cellHeaderBody5.Phrase  = new Phrase("Sisa", bold_font);
                headerTable3.AddCell(cellHeaderBody5);

                // Mata Uang
                cellHeaderBody5a.Phrase = new Phrase(currencyCode, normal_font);
                headerTable3.AddCell(cellHeaderBody5a);

                // Jumlah
                cellHeaderBody5a.Phrase = new Phrase((res * -1).ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
                cellHeaderBody5a.HorizontalAlignment = Element.ALIGN_RIGHT; // Override default to center
                headerTable3.AddCell(cellHeaderBody5a);
            }

            string total = count_price.ToString("#,##0.00", new CultureInfo("id-ID"));

            // New Line
            cellHeaderBody4a.Colspan = 7;
            cellHeaderBody4a.Phrase  = new Phrase(" ", normal_font);
            headerTable3.AddCell(cellHeaderBody4a);

            // Terbilang
            cellHeaderBody4a.Colspan             = 7;
            cellHeaderBody4a.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody4a.Phrase = new Phrase("Terbilang: " + Nom(grandTotal, currencyCode, currencydescription), normal_font);
            headerTable3.AddCell(cellHeaderBody4a);

            // New Line
            cellHeaderBody4a.Colspan = 7;
            cellHeaderBody4a.Phrase  = new Phrase(" ", normal_font);
            headerTable3.AddCell(cellHeaderBody4a);

            // Beban Unit
            cellHeaderBody4.Colspan             = 7;
            cellHeaderBody4.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody4.Phrase = new Phrase("Beban Unit :", bold_font);
            headerTable3.AddCell(cellHeaderBody4);

            cellHeader3.AddElement(headerTable3);
            headerTable_B.AddCell(cellHeader3);
            cellHeader4.AddElement(headerTable4);
            headerTable_B.AddCell(cellHeader4);
            document.Add(headerTable_B);
            #endregion Header

            #region NewCheckbox
            var unitCosts = viewModel.UnitCosts.GroupBy(s => s.UnitId).OrderBy(s => s.Key);

            List <PdfFormField> annotations = new List <PdfFormField>();
            foreach (var item in unitCosts)
            {
                PdfPCell cellform = new PdfPCell()
                {
                    Border = Rectangle.NO_BORDER
                };
                cellform.FixedHeight = 5f;

                //initiate form checkbox
                PdfFormField    _checkGroup = PdfFormField.CreateEmpty(writer);
                RadioCheckField _radioG;
                PdfFormField    _radioField1;
                Rectangle       kotak = new Rectangle(100, 100);
                _radioG             = new RadioCheckField(writer, kotak, "abc", "Yes");
                _radioG.CheckType   = RadioCheckField.TYPE_CHECK;
                _radioG.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
                _radioG.BorderColor = BaseColor.Black;
                _radioG.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;

                _radioG.Checked = true;
                bool flag = true;


                _radioG.Rotation = 0;
                _radioG.Options  = TextField.READ_ONLY;
                _radioField1     = _radioG.CheckField;

                cellform.CellEvent
                    = new BebanUnitEvent(_checkGroup, _radioField1, 1);
                headerTable3a.AddCell(cellform);

                // Beban Unit Item
                if (item.Key == 0)
                {
                    cellHeaderBody.Phrase = new Phrase("......", normal_font_8);
                }
                else
                {
                    cellHeaderBody.Phrase = new Phrase(item.First().UnitName, normal_font_8);
                }
                cellHeaderBody.HorizontalAlignment = Element.ALIGN_LEFT;
                headerTable3a.AddCell(cellHeaderBody);

                cellHeaderBody.Phrase = new Phrase("", normal_font_8);

                if (!flag)
                {
                    cellHeaderBody.Phrase = new Phrase($"...........", normal_font_8);
                    headerTable3a.AddCell(cellHeaderBody);
                }
                else
                {
                    var nom = item.Sum(s => s.Amount).ToString("#,##0.00", new CultureInfo("id-ID"));

                    // Beban Unit Item Mata Uang
                    cellHeaderBody.Phrase = new Phrase(currencyCode, normal_font_8);
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_RIGHT;
                    headerTable3a.AddCell(cellHeaderBody);

                    // Beban Unit Item Nominal
                    cellHeaderBody.Phrase = new Phrase(nom, normal_font_8);
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_RIGHT;
                    headerTable3a.AddCell(cellHeaderBody);
                }

                // Empty space
                cellHeaderBody.Phrase = new Phrase(" ", normal_font_8);
                headerTable3a.AddCell(cellHeaderBody);

                annotations.Add(_checkGroup);
            }

            for (var i = 0; i < 9 - (3 * (unitCosts.Count() % 3)); i++)
            {
                cellHeaderBody.Phrase = new Phrase(" ", normal_font);
                headerTable3a.AddCell(cellHeaderBody);
            }

            cellHeader3a.AddElement(headerTable3a);
            headerTable_C.AddCell(cellHeader3a);
            document.Add(headerTable_C);

            foreach (var annotation in annotations)
            {
                writer.AddAnnotation(annotation);
            }
            #endregion


            #region Footer
            PdfPTable table = new PdfPTable(5)
            {
                WidthPercentage = 97
            };
            float[] widths = new float[] { 1f, 1f, 1f, 1f, 1f };
            table.SetWidths(widths);
            PdfPCell cell = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_CENTER,
                VerticalAlignment   = Element.ALIGN_MIDDLE,
            };

            cell.Phrase = new Phrase(" ", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("", normal_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("Menyetujui,", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("Diperiksa,", normal_font);
            table.AddCell(cell);
            cell.Colspan = 2;
            cell.Phrase  = new Phrase("Mengetahui,", normal_font);
            table.AddCell(cell);
            cell.Colspan = 1;
            cell.Phrase  = new Phrase("Pembuat laporan,", normal_font);
            table.AddCell(cell);

            for (var i = 0; i < 11; i++)
            {
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
            }

            cell.Phrase = new Phrase("(..................)", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("(..................)", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("(..................)", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("(..................)", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase($"({viewModel.Header.CreatedBy})", normal_font);
            table.AddCell(cell);

            //cell.Phrase = new Phrase("Kasir", normal_font);
            //table.AddCell(cell);
            //cell.Phrase = new Phrase("Verifikasi", normal_font);
            //table.AddCell(cell);
            //cell.Phrase = new Phrase($"..................", normal_font);
            //table.AddCell(cell);
            //cell.Phrase = new Phrase(viewModel.Header.SuppliantUnitName, normal_font);
            //table.AddCell(cell);

            document.Add(table);
            #endregion Footer

            document.Close();
            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;

            return(stream);
        }
        public MemoryStream GeneratePdfTemplate(VBRealizationDocumentNonPOViewModel viewModel, int timeoffsset)
        {
            const int MARGIN          = 20;
            const int MARGIN_VERTICAL = 10;

            Font header_font      = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18);
            Font normal_font      = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11);
            Font normal_font_8    = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9);
            Font bold_font        = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11);
            Font bold_font_8      = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            Font note_font        = FontFactory.GetFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            Font bold_italic_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12);
            Font Title_bold_font  = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 13);

            Document     document = new Document(PageSize.A4, MARGIN_VERTICAL, MARGIN_VERTICAL, MARGIN, MARGIN);
            MemoryStream stream   = new MemoryStream();
            PdfWriter    writer   = PdfWriter.GetInstance(document, stream);

            document.Open();

            #region Header
            PdfPTable headerTable_A = new PdfPTable(2);
            PdfPTable headerTable_B = new PdfPTable(1);
            PdfPTable headerTable_C = new PdfPTable(1);
            PdfPTable headerTable1  = new PdfPTable(1);
            PdfPTable headerTable2  = new PdfPTable(1);
            PdfPTable headerTable3  = new PdfPTable(7);
            PdfPTable headerTable3a = new PdfPTable(7);
            PdfPTable headerTable3b = new PdfPTable(5);

            PdfPTable headerTable4 = new PdfPTable(2);

            headerTable_A.SetWidths(new float[] { 10f, 10f });
            headerTable_A.WidthPercentage = 100;
            headerTable3.SetWidths(new float[] { 5f, 15f, 15f, 15f, 20f, 15f, 20f });
            headerTable3.WidthPercentage = 110;
            headerTable3a.SetWidths(new float[] { 3f, 15f, 5f, 15f, 15f, 15f, 16f });
            headerTable3a.WidthPercentage = 110;
            headerTable3b.SetWidths(new float[] { 3f, 15f, 5f, 15f, 62f });
            headerTable3b.WidthPercentage = 110;
            headerTable4.SetWidths(new float[] { 10f, 40f });
            headerTable4.WidthPercentage = 100;

            PdfPCell cellHeader1 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeader2 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeader3 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeader4 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeader3a = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody1 = new PdfPCell()
            {
            };
            PdfPCell cellHeaderBody1a = new PdfPCell()
            {
                BorderWidthTop = 2
            };
            PdfPCell cellHeaderBody1a1 = new PdfPCell()
            {
            };
            PdfPCell cellHeaderBody1a2 = new PdfPCell()
            {
            };
            PdfPCell cellHeaderBody1b = new PdfPCell()
            {
                BorderWidthTop = 2
            };
            PdfPCell cellHeaderBody1b1 = new PdfPCell()
            {
            };
            PdfPCell cellHeaderBody1b2 = new PdfPCell()
            {
            };
            PdfPCell cellHeaderBody1c = new PdfPCell()
            {
            };
            PdfPCell cellHeaderBody2 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody3 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody4 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody4a = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody4b = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody5 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody5a = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody6 = new PdfPCell()
            {
            };

            cellHeader1.AddElement(headerTable1);
            headerTable_A.AddCell(cellHeader1);
            cellHeader2.AddElement(headerTable2);
            headerTable_A.AddCell(cellHeader2);
            document.Add(headerTable_A);

            cellHeaderBody.HorizontalAlignment    = Element.ALIGN_LEFT;
            cellHeaderBody1.HorizontalAlignment   = Element.ALIGN_CENTER;
            cellHeaderBody1a.HorizontalAlignment  = Element.ALIGN_RIGHT;
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_RIGHT;
            cellHeaderBody1a2.HorizontalAlignment = Element.ALIGN_RIGHT;
            cellHeaderBody1b.HorizontalAlignment  = Element.ALIGN_CENTER;
            cellHeaderBody1b1.HorizontalAlignment = Element.ALIGN_CENTER;
            cellHeaderBody1b2.HorizontalAlignment = Element.ALIGN_CENTER;
            cellHeaderBody1c.HorizontalAlignment  = Element.ALIGN_CENTER;
            cellHeaderBody2.HorizontalAlignment   = Element.ALIGN_CENTER;
            cellHeaderBody3.HorizontalAlignment   = Element.ALIGN_RIGHT;
            cellHeaderBody4.HorizontalAlignment   = Element.ALIGN_CENTER;
            cellHeaderBody4a.HorizontalAlignment  = Element.ALIGN_CENTER;
            cellHeaderBody4b.HorizontalAlignment  = Element.ALIGN_LEFT;
            cellHeaderBody5.HorizontalAlignment   = Element.ALIGN_RIGHT;
            cellHeaderBody5a.HorizontalAlignment  = Element.ALIGN_CENTER;
            cellHeaderBody6.HorizontalAlignment   = Element.ALIGN_LEFT;

            // Document title
            cellHeaderBody2.Colspan = 7;
            cellHeaderBody2.Phrase  = new Phrase("REALISASI VB INKLARING TANPA PO", bold_font);
            headerTable3.AddCell(cellHeaderBody2);

            // Document number
            cellHeaderBody3.Colspan = 7;
            cellHeaderBody3.Phrase  = new Phrase($"{viewModel.DocumentNo}", bold_font);
            headerTable3.AddCell(cellHeaderBody3);

            // Realisasi VB Bagian
            cellHeaderBody3.Colspan             = 7;
            cellHeaderBody3.HorizontalAlignment = Element.ALIGN_LEFT; // Override default to right
            cellHeaderBody3.Phrase = new Phrase($"Realisasi VB Bagian: {viewModel.Unit.Name}", bold_font);
            headerTable3.AddCell(cellHeaderBody3);

            // Tanggal
            cellHeaderBody3.Colspan             = 7;
            cellHeaderBody3.HorizontalAlignment = Element.ALIGN_LEFT; // Override default to right
            cellHeaderBody3.Phrase = new Phrase($"Tanggal: {viewModel.Date?.AddHours(timeoffsset).ToString("dd MMMM yyyy", new CultureInfo("id-ID"))}", bold_font);
            headerTable3.AddCell(cellHeaderBody3);

            // New line
            cellHeaderBody3.Phrase = new Phrase(" ", normal_font);
            headerTable3.AddCell(cellHeaderBody3);

            // Table header
            cellHeaderBody1.Phrase = new Phrase("No", normal_font);
            headerTable3.AddCell(cellHeaderBody1);
            cellHeaderBody1.Phrase = new Phrase("Tanggal", normal_font);
            headerTable3.AddCell(cellHeaderBody1);
            cellHeaderBody1.Colspan = 2;
            cellHeaderBody1.Phrase  = new Phrase("Keterangan", normal_font);
            headerTable3.AddCell(cellHeaderBody1);
            cellHeaderBody1.Colspan = 1;
            cellHeaderBody1.Phrase  = new Phrase("No. BL / AWB", normal_font);
            headerTable3.AddCell(cellHeaderBody1);
            cellHeaderBody1.Phrase = new Phrase("Mata Uang", normal_font);
            headerTable3.AddCell(cellHeaderBody1);
            cellHeaderBody1.Phrase = new Phrase("Jumlah", normal_font);
            headerTable3.AddCell(cellHeaderBody1);

            int index = 1;
            /*decimal count_price = 0;*/
            /*decimal total_all = 0;*/
            decimal total_realization = 0;

            decimal ppn_manually = 0;
            decimal pph_supplier = 0;
            decimal pph_danliris = 0;

            var currencyCode        = viewModel.Currency.Code;
            var currencydescription = viewModel.Currency.Description;

            foreach (var itm in viewModel.Items)
            {
                // No
                cellHeaderBody1.Phrase = new Phrase(index.ToString(), normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER;
                headerTable3.AddCell(cellHeaderBody1);
                index++;

                // Tanggal
                cellHeaderBody1.Phrase = new Phrase(itm.DateDetail?.AddHours(timeoffsset).ToString("dd/MM/yyyy"), normal_font);
                headerTable3.AddCell(cellHeaderBody1);

                // Keterangan
                cellHeaderBody1.Colspan             = 2;
                cellHeaderBody1.Phrase              = new Phrase(itm.Remark, normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_LEFT;
                headerTable3.AddCell(cellHeaderBody1);

                // No. BL / AWB
                cellHeaderBody1.Colspan             = 1;
                cellHeaderBody1.Phrase              = new Phrase(itm.BLAWBNumber, normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_LEFT;
                headerTable3.AddCell(cellHeaderBody1);

                if (itm.IsGetPPn)
                {
                    /*var temp = itm.Amount * 0.1m;
                     * total_all = itm.Amount + temp;*/

                    ppn_manually += itm.PPnAmount;
                }

                /*else
                 * {
                 *  total_all = itm.Amount;
                 * }*/

                if (itm.IsGetPPh)
                {
                    if (itm.IncomeTaxBy == "Supplier")
                    {
                        pph_supplier += itm.PPhAmount;
                    }
                    else
                    {
                        pph_danliris += itm.PPhAmount;
                    }
                }

                // Mata Uang
                cellHeaderBody1.Colspan             = 1;
                cellHeaderBody1.Phrase              = new Phrase(currencyCode, normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER;
                headerTable3.AddCell(cellHeaderBody1);

                // Jumlah
                cellHeaderBody1.Phrase = new Phrase(itm.Amount.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_RIGHT; // Override default to center
                headerTable3.AddCell(cellHeaderBody1);

                /*count_price += total_all;*/
                total_realization += itm.Amount;
            }

            // Jumlah Realisasi
            cellHeaderBody1a.Colspan             = 5;
            cellHeaderBody1a.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody1a.Phrase = new Phrase("Jumlah Realisasi", normal_font);
            headerTable3.AddCell(cellHeaderBody1a);

            // Mata Uang
            cellHeaderBody1b.Phrase = new Phrase(currencyCode, normal_font);
            headerTable3.AddCell(cellHeaderBody1b);

            // Jumlah
            cellHeaderBody1a.Phrase = new Phrase(total_realization.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
            cellHeaderBody1a.HorizontalAlignment = Element.ALIGN_RIGHT;
            headerTable3.AddCell(cellHeaderBody1a);

            // PPn
            cellHeaderBody1a1.Colspan             = 5;
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody1a1.Phrase = new Phrase("PPN", normal_font);
            headerTable3.AddCell(cellHeaderBody1a1);

            // Mata Uang
            cellHeaderBody1b1.Phrase = new Phrase(currencyCode, normal_font);
            headerTable3.AddCell(cellHeaderBody1b1);

            // Jumlah
            cellHeaderBody1a1.Phrase = new Phrase(ppn_manually.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_RIGHT;
            headerTable3.AddCell(cellHeaderBody1a1);

            // PPh ditanggung Dan Liris
            cellHeaderBody1a1.Colspan             = 5;
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody1a1.Phrase = new Phrase("PPh ditanggung Dan Liris", normal_font);
            headerTable3.AddCell(cellHeaderBody1a1);

            // Mata Uang
            cellHeaderBody1b1.Phrase = new Phrase(currencyCode, normal_font);
            headerTable3.AddCell(cellHeaderBody1b1);

            // Jumlah
            cellHeaderBody1a1.Phrase = new Phrase(pph_danliris.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_RIGHT;
            headerTable3.AddCell(cellHeaderBody1a1);

            // PPh ditanggung Supplier
            cellHeaderBody1a1.Colspan             = 5;
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody1a1.Phrase = new Phrase("PPh ditanggung Supplier", normal_font);
            headerTable3.AddCell(cellHeaderBody1a1);

            // Mata Uang
            cellHeaderBody1b1.Phrase = new Phrase(currencyCode, normal_font);
            headerTable3.AddCell(cellHeaderBody1b1);

            // Jumlah
            cellHeaderBody1a1.Phrase = new Phrase(pph_supplier.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
            cellHeaderBody1a1.HorizontalAlignment = Element.ALIGN_RIGHT;
            headerTable3.AddCell(cellHeaderBody1a1);

            // Total Keseluruhan
            cellHeaderBody1a2.Colspan             = 5;
            cellHeaderBody1a2.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody1a2.Phrase = new Phrase("Total", normal_font);
            headerTable3.AddCell(cellHeaderBody1a2);

            // Mata Uang
            cellHeaderBody1b2.Phrase = new Phrase(currencyCode, normal_font);
            headerTable3.AddCell(cellHeaderBody1b2);

            // Jumlah
            var grandTotal = total_realization + ppn_manually - pph_supplier;
            cellHeaderBody1a2.Phrase = new Phrase(grandTotal.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
            cellHeaderBody1a2.HorizontalAlignment = Element.ALIGN_RIGHT;
            headerTable3.AddCell(cellHeaderBody1a2);

            var vbDate = viewModel.VBDocument?.Date?.AddHours(timeoffsset).ToString("dd-MMMM-yy", new CultureInfo("id-ID"));
            if (viewModel.VBNonPOType == "Tanpa Nomor VB")
            {
                if (viewModel.VBDocument != null && !string.IsNullOrWhiteSpace(viewModel.VBDocument?.DocumentNo))
                {
                    vbDate = viewModel.VBDocument?.Date?.AddHours(timeoffsset).ToString("dd-MMMM-yy", new CultureInfo("id-ID"));
                }
                else
                {
                    vbDate = "";
                }
            }

            // Tanggal VB
            cellHeaderBody6.Colspan = 3;
            cellHeaderBody6.Phrase  = new Phrase($"Tanggal VB: {vbDate}", normal_font);
            headerTable3.AddCell(cellHeaderBody6);

            // No VB
            cellHeaderBody1.Colspan             = 2;
            cellHeaderBody1.Phrase              = new Phrase($"No.VB: {viewModel.VBDocument?.DocumentNo}", normal_font);
            cellHeaderBody1.HorizontalAlignment = Element.ALIGN_LEFT;
            headerTable3.AddCell(cellHeaderBody1);

            if (viewModel.VBDocument == null)
            {
                // Mata Uang
                cellHeaderBody1.Colspan             = 1;
                cellHeaderBody1.Phrase              = new Phrase(currencyCode, normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER;
                headerTable3.AddCell(cellHeaderBody1);

                // Jumlah
                cellHeaderBody1.Phrase = new Phrase(0.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_RIGHT; // Override default to center
                headerTable3.AddCell(cellHeaderBody1);
            }
            else
            {
                // Mata Uang
                cellHeaderBody1.Colspan             = 1;
                cellHeaderBody1.Phrase              = new Phrase(currencyCode, normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_CENTER;
                headerTable3.AddCell(cellHeaderBody1);

                // Jumlah
                cellHeaderBody1.Phrase = new Phrase($"{viewModel.VBDocument?.Amount.GetValueOrDefault().ToString("#,##0.00", new CultureInfo("id-ID"))}", normal_font);
                cellHeaderBody1.HorizontalAlignment = Element.ALIGN_RIGHT; // Override default to center
                headerTable3.AddCell(cellHeaderBody1);
            }

            var priceterbilang = grandTotal;
            var res            = grandTotal - (viewModel.VBDocument == null ? 0 : viewModel.VBDocument.Amount.GetValueOrDefault());

            if (res > 0)
            {
                // Kurang
                cellHeaderBody5.Colspan = 5;
                cellHeaderBody5.Phrase  = new Phrase("Kurang", bold_font);
                headerTable3.AddCell(cellHeaderBody5);

                // Mata Uang
                cellHeaderBody5a.Phrase = new Phrase(currencyCode, normal_font);
                headerTable3.AddCell(cellHeaderBody5a);

                // Jumlah
                cellHeaderBody5a.Phrase = new Phrase("(" + res.ToString("#,##0.00", new CultureInfo("id-ID")) + ")", normal_font);
                cellHeaderBody5a.HorizontalAlignment = Element.ALIGN_RIGHT; // Override default to center
                headerTable3.AddCell(cellHeaderBody5a);
            }
            else
            {
                // Sisa
                cellHeaderBody5.Colspan = 5;
                cellHeaderBody5.Phrase  = new Phrase("Sisa", bold_font);
                headerTable3.AddCell(cellHeaderBody5);

                // Mata Uang
                cellHeaderBody5a.Phrase = new Phrase(currencyCode, normal_font);
                headerTable3.AddCell(cellHeaderBody5a);

                // Jumlah
                cellHeaderBody5a.Phrase = new Phrase($"{(res * -1).ToString("#,##0.00", new CultureInfo("id-ID"))}", normal_font);
                cellHeaderBody5a.HorizontalAlignment = Element.ALIGN_RIGHT; // Override default to center
                headerTable3.AddCell(cellHeaderBody5a);
            }

            string total = grandTotal.ToString("#,##0.00", new CultureInfo("id-ID"));

            // New Line
            cellHeaderBody4a.Colspan = 7;
            cellHeaderBody4a.Phrase  = new Phrase(" ", normal_font);
            headerTable3.AddCell(cellHeaderBody4a);

            // Terbilang
            cellHeaderBody4a.Colspan             = 7;
            cellHeaderBody4a.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody4a.Phrase = new Phrase("Terbilang: " + Nom(grandTotal, currencyCode, currencydescription), normal_font);
            headerTable3.AddCell(cellHeaderBody4a);

            // New Line
            cellHeaderBody4a.Colspan = 7;
            cellHeaderBody4a.Phrase  = new Phrase(" ", normal_font);
            headerTable3.AddCell(cellHeaderBody4a);

            cellHeader3.AddElement(headerTable3);
            headerTable_B.AddCell(cellHeader3);
            cellHeader4.AddElement(headerTable4);
            headerTable_B.AddCell(cellHeader4);
            document.Add(headerTable_B);

            // Beban Unit
            cellHeaderBody.Colspan             = 4;
            cellHeaderBody.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody.Phrase = new Phrase("Beban Unit:", bold_font);
            headerTable3a.AddCell(cellHeaderBody);

            if (pph_supplier != 0 || pph_danliris != 0)
            {
                // Header PPH23
                cellHeaderBody.Colspan             = 1;
                cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER;
                cellHeaderBody.Phrase = new Phrase("PPH 23", normal_font_8);
                headerTable3a.AddCell(cellHeaderBody);

                if (ppn_manually != 0)
                {
                    // Header PPN
                    cellHeaderBody.Colspan             = 1;
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER;
                    cellHeaderBody.Phrase = new Phrase("PPN", normal_font_8);
                    headerTable3a.AddCell(cellHeaderBody);

                    // Empty space
                    cellHeaderBody.Colspan             = 1;
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER;
                    cellHeaderBody.Phrase = new Phrase(" ", normal_font_8);
                    headerTable3a.AddCell(cellHeaderBody);
                }
                else
                {
                    // Empty space
                    cellHeaderBody.Colspan             = 2;
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER;
                    cellHeaderBody.Phrase = new Phrase(" ", normal_font_8);
                    headerTable3a.AddCell(cellHeaderBody);
                }
            }
            else
            {
                if (ppn_manually != 0)
                {
                    // Header PPN
                    cellHeaderBody.Colspan             = 1;
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER;
                    cellHeaderBody.Phrase = new Phrase("PPN", normal_font_8);
                    headerTable3a.AddCell(cellHeaderBody);

                    // Empty space
                    cellHeaderBody.Colspan             = 2;
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER;
                    cellHeaderBody.Phrase = new Phrase(" ", normal_font_8);
                    headerTable3a.AddCell(cellHeaderBody);
                }
                else
                {
                    // Empty space
                    cellHeaderBody.Colspan             = 3;
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER;
                    cellHeaderBody.Phrase = new Phrase(" ", normal_font_8);
                    headerTable3a.AddCell(cellHeaderBody);
                }
            }

            // New Line
            cellHeaderBody.Colspan = 7;
            cellHeaderBody.Phrase  = new Phrase(" ", normal_font);
            headerTable3a.AddCell(cellHeaderBody);
            #endregion Header

            #region NewCheckbox
            var layoutOrderOther = viewModel.UnitCosts.ToList().FirstOrDefault(s => s.Unit.VBDocumentLayoutOrder == 10);
            var unitCost12       = viewModel.UnitCosts.ToList().FirstOrDefault(s => s.Unit.VBDocumentLayoutOrder == 12);

            if (unitCost12 != null)
            {
                unitCost12.Unit.VBDocumentLayoutOrder = 10;
            }

            if (layoutOrderOther != null)
            {
                layoutOrderOther.Unit.VBDocumentLayoutOrder = 12;
            }

            var items = viewModel.UnitCosts.Where(element => element.IsSelected).OrderBy(s => s.Unit.VBDocumentLayoutOrder).ToList();
            List <PdfFormField> annotations = new List <PdfFormField>();
            foreach (var item in items)
            {
                PdfPCell cellform = new PdfPCell()
                {
                    Border = Rectangle.NO_BORDER
                };
                cellform.FixedHeight = 5f;

                // Initiate form checkbox
                PdfFormField    _checkGroup = PdfFormField.CreateEmpty(writer);
                RadioCheckField _radioG;
                PdfFormField    _radioField1;
                Rectangle       kotak = new Rectangle(100, 100);
                _radioG             = new RadioCheckField(writer, kotak, "abc", "Yes");
                _radioG.CheckType   = RadioCheckField.TYPE_CHECK;
                _radioG.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
                _radioG.BorderColor = BaseColor.Black;
                _radioG.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;

                _radioG.Checked = item.IsSelected;
                bool flag = item.IsSelected;

                _radioG.Rotation = 0;
                _radioG.Options  = TextField.READ_ONLY;
                _radioField1     = _radioG.CheckField;

                cellform.CellEvent
                    = new BebanUnitEvent(_checkGroup, _radioField1, 1);
                headerTable3a.AddCell(cellform);

                // Beban Unit Item
                cellHeaderBody.Colspan = 1;
                if (string.IsNullOrEmpty(item.Unit.Name))
                {
                    cellHeaderBody.Phrase = new Phrase("......", normal_font_8);
                }
                else
                {
                    cellHeaderBody.Phrase = new Phrase(item.Unit.Name, normal_font_8);
                }
                cellHeaderBody.HorizontalAlignment = Element.ALIGN_LEFT;
                headerTable3a.AddCell(cellHeaderBody);

                cellHeaderBody.Phrase = new Phrase("", normal_font_8);

                if (!flag)
                {
                    cellHeaderBody.Colspan = 2;
                    cellHeaderBody.Phrase  = new Phrase($"...........", normal_font_8);
                    headerTable3a.AddCell(cellHeaderBody);
                }
                else
                {
                    var nom = item.Amount.ToString("#,##0.00", new CultureInfo("id-ID"));

                    // Beban Unit Item Mata Uang
                    cellHeaderBody.Colspan             = 1;
                    cellHeaderBody.Phrase              = new Phrase(currencyCode, normal_font_8);
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_RIGHT;
                    headerTable3a.AddCell(cellHeaderBody);

                    // Beban Unit Item Nominal
                    cellHeaderBody.Colspan             = 1;
                    cellHeaderBody.Phrase              = new Phrase(nom, normal_font_8);
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_RIGHT;
                    headerTable3a.AddCell(cellHeaderBody);
                }

                //PPh
                if (pph_supplier != 0 && pph_danliris == 0)
                {
                    decimal pph_supplier_unit_item = ((item.Amount / grandTotal) * pph_supplier);

                    cellHeaderBody.Colspan             = 1;
                    cellHeaderBody.Phrase              = new Phrase(pph_supplier_unit_item.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font_8);
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER;
                    headerTable3a.AddCell(cellHeaderBody);
                }
                else if (pph_supplier == 0 && pph_danliris != 0)
                {
                    decimal pph_danliris_unit_item = ((item.Amount / grandTotal) * pph_danliris);

                    cellHeaderBody.Colspan             = 1;
                    cellHeaderBody.Phrase              = new Phrase(pph_danliris_unit_item.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font_8);
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER;
                    headerTable3a.AddCell(cellHeaderBody);
                }
                else if (pph_supplier != 0 && pph_danliris != 0)
                {
                    decimal pph_unit_item = ((item.Amount / grandTotal) * (pph_supplier + pph_danliris));

                    cellHeaderBody.Colspan             = 1;
                    cellHeaderBody.Phrase              = new Phrase(pph_unit_item.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font_8);
                    cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER;
                    headerTable3a.AddCell(cellHeaderBody);
                }

                //PPn
                if (ppn_manually != 0)
                {
                    decimal ppn_unit_item = ((item.Amount / grandTotal) * ppn_manually);

                    if (pph_danliris == 0 && pph_supplier == 0)
                    {
                        cellHeaderBody.Colspan             = 1;
                        cellHeaderBody.Phrase              = new Phrase(ppn_unit_item.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font_8);
                        cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerTable3a.AddCell(cellHeaderBody);

                        cellHeaderBody.Colspan = 1;
                        cellHeaderBody.Phrase  = new Phrase(" ", normal_font_8);
                        headerTable3a.AddCell(cellHeaderBody);
                    }
                    else
                    {
                        cellHeaderBody.Colspan             = 1;
                        cellHeaderBody.Phrase              = new Phrase(ppn_unit_item.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font_8);
                        cellHeaderBody.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerTable3a.AddCell(cellHeaderBody);
                    }
                }
                else
                {
                    if (pph_danliris == 0 && pph_supplier == 0)
                    {
                        cellHeaderBody.Colspan = 2;
                        cellHeaderBody.Phrase  = new Phrase(" ", normal_font_8);
                        headerTable3a.AddCell(cellHeaderBody);
                    }
                    else
                    {
                        cellHeaderBody.Colspan = 1;
                        cellHeaderBody.Phrase  = new Phrase(" ", normal_font_8);
                        headerTable3a.AddCell(cellHeaderBody);
                    }
                }

                // Empty space
                cellHeaderBody.Colspan = 1;
                cellHeaderBody.Phrase  = new Phrase(" ", normal_font_8);
                headerTable3a.AddCell(cellHeaderBody);

                annotations.Add(_checkGroup);
            }

            for (var i = 0; i < 9 - (3 * (items.Count() % 3)); i++)
            {
                cellHeaderBody.Phrase = new Phrase(" ", normal_font);
                headerTable3a.AddCell(cellHeaderBody);
            }

            cellHeader3a.AddElement(headerTable3a);
            headerTable_C.AddCell(cellHeader3a);

            var cellLeft = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_MIDDLE,
            };

            var emptyBorder = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };

            cellLeft.Colspan = 5;
            cellLeft.Phrase  = new Phrase("\n\nKeterangan: ", normal_font);
            headerTable3b.AddCell(cellLeft);

            cellLeft.Colspan = 1;
            cellLeft.Phrase  = new Phrase("", normal_font);
            headerTable3b.AddCell(cellLeft);
            cellLeft.Colspan = 4;
            cellLeft.Phrase  = new Phrase(viewModel.Remark, normal_font);
            headerTable3b.AddCell(cellLeft);
            emptyBorder.AddElement(headerTable3b);
            headerTable_C.AddCell(emptyBorder);

            document.Add(headerTable_C);

            foreach (var annotation in annotations)
            {
                writer.AddAnnotation(annotation);
            }
            #endregion

            #region Keterangan
            cellHeaderBody4a.Colspan             = 7;
            cellHeaderBody4a.HorizontalAlignment = Element.ALIGN_LEFT;
            cellHeaderBody4a.Phrase = new Phrase("Keterangan: " + viewModel.Remark, normal_font);
            headerTable3.AddCell(cellHeaderBody4a);
            #endregion

            #region Footer
            PdfPTable table = new PdfPTable(5)
            {
                WidthPercentage = 97
            };
            float[] widths = new float[] { 1f, 1f, 1f, 1f, 1f };
            table.SetWidths(widths);
            PdfPCell cell = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_CENTER,
                VerticalAlignment   = Element.ALIGN_MIDDLE,
            };

            cell.Phrase = new Phrase("\n\n", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("\n\n", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("\n\n", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("\n\n", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("\n\n", normal_font);
            table.AddCell(cell);

            // Menyetujui
            cell.Phrase = new Phrase("Menyetujui,", normal_font);
            table.AddCell(cell);

            // Diperiksa
            cell.Phrase = new Phrase("Diperiksa,", normal_font);
            table.AddCell(cell);

            // Mengetahui
            cell.Colspan = 2;
            cell.Phrase  = new Phrase("Mengetahui,", normal_font);
            table.AddCell(cell);

            // Pembuat laporan
            cell.Colspan = 1;
            cell.Phrase  = new Phrase("Pembuat laporan,", normal_font);
            table.AddCell(cell);

            for (var i = 0; i < 11; i++)
            {
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
            }

            cell.Phrase = new Phrase("(..................)", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("(..................)", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("(..................)", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase($"(..................)", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase($"({viewModel.CreatedBy})", normal_font);
            table.AddCell(cell);
            document.Add(table);
            #endregion Footer

            document.Close();
            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;

            return(stream);
        }
Пример #11
0
// ---------------------------------------------------------------------------

        /**
         * Creates a PDF document.
         */
        public byte[] CreatePdf()
        {
            using (MemoryStream ms = new MemoryStream()) {
                using (Document document = new Document()) {
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    document.Open();
                    jsString = File.ReadAllText(
                        Path.Combine(Utility.ResourceJavaScript, RESOURCE)
                        );
                    writer.AddJavaScript(jsString);

                    PdfContentByte canvas = writer.DirectContent;
                    Font           font   = new Font(Font.FontFamily.HELVETICA, 18);
                    Rectangle      rect;
                    PdfFormField   field;
                    PdfFormField   radiogroup = PdfFormField.CreateRadioButton(writer, true);
                    radiogroup.FieldName = "language";
                    RadioCheckField radio;
                    for (int i = 0; i < LANGUAGES.Length; i++)
                    {
                        rect                  = new Rectangle(40, 806 - i * 40, 60, 788 - i * 40);
                        radio                 = new RadioCheckField(writer, rect, null, LANGUAGES[i]);
                        radio.BorderColor     = GrayColor.GRAYBLACK;
                        radio.BackgroundColor = GrayColor.GRAYWHITE;
                        radio.CheckType       = RadioCheckField.TYPE_CIRCLE;
                        field                 = radio.RadioField;
                        radiogroup.AddKid(field);
                        ColumnText.ShowTextAligned(
                            canvas, Element.ALIGN_LEFT,
                            new Phrase(LANGUAGES[i], font), 70, 790 - i * 40, 0
                            );
                    }
                    writer.AddAnnotation(radiogroup);

                    PdfAppearance[] onOff = new PdfAppearance[2];
                    onOff[0] = canvas.CreateAppearance(20, 20);
                    onOff[0].Rectangle(1, 1, 18, 18);
                    onOff[0].Stroke();
                    onOff[1] = canvas.CreateAppearance(20, 20);
                    onOff[1].SetRGBColorFill(255, 128, 128);
                    onOff[1].Rectangle(1, 1, 18, 18);
                    onOff[1].FillStroke();
                    onOff[1].MoveTo(1, 1);
                    onOff[1].LineTo(19, 19);
                    onOff[1].MoveTo(1, 19);
                    onOff[1].LineTo(19, 1);
                    onOff[1].Stroke();
                    RadioCheckField checkbox;
                    for (int i = 0; i < LANGUAGES.Length; i++)
                    {
                        rect     = new Rectangle(180, 806 - i * 40, 200, 788 - i * 40);
                        checkbox = new RadioCheckField(writer, rect, LANGUAGES[i], "on");
                        // checkbox.CheckType = RadioCheckField.TYPE_CHECK;
                        field = checkbox.CheckField;
                        field.SetAppearance(
                            PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]
                            );
                        field.SetAppearance(
                            PdfAnnotation.APPEARANCE_NORMAL, "On", onOff[1]
                            );
                        writer.AddAnnotation(field);
                        ColumnText.ShowTextAligned(
                            canvas, Element.ALIGN_LEFT,
                            new Phrase(LANGUAGES[i], font), 210,
                            790 - i * 40, 0
                            );
                    }
                    rect = new Rectangle(300, 806, 370, 788);
                    PushbuttonField button = new PushbuttonField(writer, rect, "Buttons");
                    button.BackgroundColor          = new GrayColor(0.75f);
                    button.BorderColor              = GrayColor.GRAYBLACK;
                    button.BorderWidth              = 1;
                    button.BorderStyle              = PdfBorderDictionary.STYLE_BEVELED;
                    button.TextColor                = GrayColor.GRAYBLACK;
                    button.FontSize                 = 12;
                    button.Text                     = "Push me";
                    button.Layout                   = PushbuttonField.LAYOUT_ICON_LEFT_LABEL_RIGHT;
                    button.ScaleIcon                = PushbuttonField.SCALE_ICON_ALWAYS;
                    button.ProportionalIcon         = true;
                    button.IconHorizontalAdjustment = 0;
                    button.Image                    = Image.GetInstance(
                        Path.Combine(Utility.ResourceImage, IMAGE)
                        );
                    field        = button.Field;
                    field.Action = PdfAction.JavaScript("this.showButtonState()", writer);
                    writer.AddAnnotation(field);
                }
                return(ms.ToArray());
            }
        }
        public MemoryStream GeneratePdfTemplate(VbWithPORequestViewModel viewModel, int clientTimeZoneOffset)
        {
            const int MARGIN = 20;

            Font header_font      = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 18);
            Font normal_font      = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11);
            Font bold_font        = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11);
            Font note_font        = FontFactory.GetFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8);
            Font bold_italic_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12);
            Font Title_bold_font  = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 13);

            Document     document = new Document(PageSize.A5.Rotate(), MARGIN, MARGIN, MARGIN, MARGIN);
            MemoryStream stream   = new MemoryStream();
            PdfWriter    writer   = PdfWriter.GetInstance(document, stream);

            document.Open();

            #region Header

            PdfPTable headerTable_A = new PdfPTable(2);
            PdfPTable headerTable_B = new PdfPTable(1);
            PdfPTable headerTable_C = new PdfPTable(1);
            PdfPTable headerTable1  = new PdfPTable(1);
            PdfPTable headerTable2  = new PdfPTable(1);
            PdfPTable headerTable3  = new PdfPTable(3);
            PdfPTable headerTable3a = new PdfPTable(10);
            PdfPTable headerTable4  = new PdfPTable(2);
            headerTable_A.SetWidths(new float[] { 10f, 10f });
            headerTable_A.WidthPercentage = 100;
            headerTable3.SetWidths(new float[] { 40f, 4f, 100f });
            headerTable3.WidthPercentage = 100;
            headerTable3a.SetWidths(new float[] { 3f, 10f, 3f, 10f, 3f, 10f, 3f, 10f, 3f, 10f });
            headerTable3a.WidthPercentage = 100;
            headerTable4.SetWidths(new float[] { 10f, 40f });
            headerTable4.WidthPercentage = 100;

            PdfPCell cellHeader1 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeader2 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeader3 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeader4 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeader3a = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody2 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            PdfPCell cellHeaderBody3 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };

            cellHeaderBody.Phrase = new Phrase("Kepada Yth.......", normal_font);
            headerTable1.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase("Kasir PT. Danliris", normal_font);
            headerTable1.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase("Di tempat", normal_font);
            headerTable1.AddCell(cellHeaderBody);

            cellHeader1.AddElement(headerTable1);
            headerTable_A.AddCell(cellHeader1);

            cellHeader2.AddElement(headerTable2);
            headerTable_A.AddCell(cellHeader2);

            document.Add(headerTable_A);

            cellHeaderBody.HorizontalAlignment  = Element.ALIGN_LEFT;
            cellHeaderBody2.HorizontalAlignment = Element.ALIGN_CENTER;
            cellHeaderBody3.HorizontalAlignment = Element.ALIGN_RIGHT;

            cellHeaderBody2.Colspan = 3;
            cellHeaderBody2.Phrase  = new Phrase("PERMOHONAN VB DENGAN PO", bold_font);
            headerTable3.AddCell(cellHeaderBody2);

            //cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            //headerTable3.AddCell(cellHeaderBody);
            //cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            //headerTable3.AddCell(cellHeaderBody);
            //cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            //headerTable3.AddCell(cellHeaderBody);

            cellHeaderBody3.Colspan = 3;
            cellHeaderBody3.Phrase  = new Phrase($"No     : {viewModel.VBNo}", normal_font);
            headerTable3.AddCell(cellHeaderBody3);

            cellHeaderBody3.Colspan = 3;
            cellHeaderBody3.Phrase  = new Phrase($"Tanggal     : {viewModel.Date?.AddHours(clientTimeZoneOffset).ToString("dd/MM/yyyy")}", normal_font);
            headerTable3.AddCell(cellHeaderBody3);

            //cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            //headerTable3.AddCell(cellHeaderBody);
            //cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            //headerTable3.AddCell(cellHeaderBody);
            //cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            //headerTable3.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("VB Uang", normal_font);
            headerTable3.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase(":", normal_font);
            headerTable3.AddCell(cellHeaderBody);

            decimal convertCurrency = 0;
            string  Usage           = "";
            string  PoNumber        = "";

            foreach (var itm1 in viewModel.Items)
            {
                PoNumber += itm1.no + ", ";

                foreach (var itm2 in itm1.Details)
                {
                    var price = itm2.priceBeforeTax * itm2.dealQuantity;
                    if (itm2.useVat && !itm2.includePpn)
                    {
                        price += price * (decimal)0.1;
                    }
                    convertCurrency += price;
                    Usage           += itm2.product.name + ", ";
                }
            }
            Usage    = Usage.Remove(Usage.Length - 2);
            PoNumber = PoNumber.Remove(PoNumber.Length - 2);

            cellHeaderBody.Phrase = new Phrase($"{viewModel.Currency.Code} " + viewModel.VBMoney.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
            headerTable3.AddCell(cellHeaderBody);


            cellHeaderBody.Phrase = new Phrase("Terbilang", normal_font);
            headerTable3.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase(":", normal_font);
            headerTable3.AddCell(cellHeaderBody);

            string TotalPaidString;
            string CurrencySay;
            if (viewModel.Currency.Code == "IDR")
            {
                TotalPaidString = NumberToTextIDN.terbilang((double)viewModel.VBMoney);
                CurrencySay     = "Rupiah";
            }
            else
            {
                TotalPaidString = NumberToTextIDN.terbilang((double)viewModel.VBMoney);
                CurrencySay     = viewModel.Currency.Description;
                CurrencySay     = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(CurrencySay.ToLower());
            }

            cellHeaderBody.Phrase = new Phrase(TotalPaidString + " " + CurrencySay, normal_font);
            headerTable3.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("No PO", normal_font);
            headerTable3.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase(":", normal_font);
            headerTable3.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase(PoNumber, normal_font);
            headerTable3.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("Total Harga PO", normal_font);
            headerTable3.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase(":", normal_font);
            headerTable3.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase($"{viewModel.Currency.Code} " + convertCurrency.ToString("#,##0.00", new CultureInfo("id-ID")), normal_font);
            headerTable3.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("Kegunaan", normal_font);
            headerTable3.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase(":", normal_font);
            headerTable3.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase(viewModel.Usage, normal_font);
            headerTable3.AddCell(cellHeaderBody);

            //cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            //headerTable3.AddCell(cellHeaderBody);
            //cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            //headerTable3.AddCell(cellHeaderBody);
            //cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            //headerTable3.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("Beban Unit  :", normal_font);
            headerTable3.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            headerTable3.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            headerTable3.AddCell(cellHeaderBody);

            cellHeader3.AddElement(headerTable3);
            headerTable_B.AddCell(cellHeader3);

            cellHeader4.AddElement(headerTable4);
            headerTable_B.AddCell(cellHeader4);

            document.Add(headerTable_B);
            //writer.AddAnnotation(_checkGroup);
            #endregion Header

            #region CheckBox
            string unit = "";
            foreach (var itm in viewModel.Items)
            {
                unit += itm.unit.Name + ",";
            }
            unit = unit.Remove(unit.Length - 1);
            var items = unit.Split(",");

            string lastitem = items[items.Length - 1];

            lastitem = lastitem.Trim();

            cellHeaderBody.Phrase = new Phrase("", normal_font);

            //Create_Box(writer,headerTable3a);

            PdfPCell cellform = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform.FixedHeight = 5f;
            //initiate form checkbox

            PdfFormField    _checkGroup = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG;
            PdfFormField    _radioField1;
            Rectangle       kotak = new Rectangle(100, 100);
            _radioG             = new RadioCheckField(writer, kotak, "abc", "Yes");
            _radioG.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG.BorderColor = BaseColor.Black;
            _radioG.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;

            if (unit.ToUpper().Contains("SPINNING 1"))
            {
                _radioG.Checked = true;
            }
            else
            {
                _radioG.Checked = false;
            }
            _radioG.Rotation = 90;
            _radioG.Options  = TextField.READ_ONLY;
            _radioField1     = _radioG.CheckField;

            cellform.CellEvent
                = new BebanUnitEvent(_checkGroup, _radioField1, 1);
            headerTable3a.AddCell(cellform);

            cellHeaderBody.Phrase = new Phrase("Spinning 1", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform1 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform1.FixedHeight = 5f;
            //initiate form checkbox

            PdfFormField    _checkGroup1 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG1;
            PdfFormField    _radioField11;
            Rectangle       kotak1 = new Rectangle(100, 100);
            _radioG1             = new RadioCheckField(writer, kotak1, "abc", "Yes");
            _radioG1.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG1.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG1.BorderColor = BaseColor.Black;
            _radioG1.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;
            if (unit.ToUpper().Contains("WEAVING 1"))
            {
                _radioG1.Checked = true;
            }
            else
            {
                _radioG1.Checked = false;
            }
            _radioG1.Rotation = 90;
            _radioG1.Options  = TextField.READ_ONLY;
            _radioField11     = _radioG1.CheckField;

            cellform1.CellEvent
                = new BebanUnitEvent(_checkGroup1, _radioField11, 1);
            headerTable3a.AddCell(cellform1);
            cellHeaderBody.Phrase = new Phrase("Weaving 1", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform2 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform2.FixedHeight = 5f;
            //initiate form checkbox
            PdfFormField    _checkGroup2 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG2;
            PdfFormField    _radioField12;
            Rectangle       kotak2 = new Rectangle(100, 100);
            _radioG2             = new RadioCheckField(writer, kotak2, "abc", "Yes");
            _radioG2.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG2.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG2.BorderColor = BaseColor.Black;
            _radioG2.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;
            if (unit.ToUpper().Contains("FINISHING"))
            {
                _radioG2.Checked = true;
            }
            else
            {
                _radioG2.Checked = false;
            }
            _radioG2.Rotation = 90;
            _radioG2.Options  = TextField.READ_ONLY;
            _radioField12     = _radioG2.CheckField;
            cellform2.CellEvent
                = new BebanUnitEvent(_checkGroup2, _radioField12, 1);
            headerTable3a.AddCell(cellform2);

            cellHeaderBody.Phrase = new Phrase("Finishing", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform3 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform3.FixedHeight = 5f;
            //initiate form checkbox
            PdfFormField    _checkGroup3 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG3;
            PdfFormField    _radioField13;
            Rectangle       kotak3 = new Rectangle(100, 100);
            _radioG3             = new RadioCheckField(writer, kotak3, "abc", "Yes");
            _radioG3.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG3.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG3.BorderColor = BaseColor.Black;
            _radioG3.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;
            if (unit.ToUpper().Contains("KONFEKSI 2A"))
            {
                _radioG3.Checked = true;
            }
            else
            {
                _radioG3.Checked = false;
            }
            _radioG3.Rotation = 90;
            _radioG3.Options  = TextField.READ_ONLY;
            _radioField13     = _radioG3.CheckField;
            cellform3.CellEvent
                = new BebanUnitEvent(_checkGroup3, _radioField13, 1);
            headerTable3a.AddCell(cellform3);

            cellHeaderBody.Phrase = new Phrase("Konfeksi 2 A", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform4 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform4.FixedHeight = 5f;
            //initiate form checkbox
            PdfFormField    _checkGroup4 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG4;
            PdfFormField    _radioField14;
            Rectangle       kotak4 = new Rectangle(100, 100);
            _radioG4             = new RadioCheckField(writer, kotak4, "abc", "Yes");
            _radioG4.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG4.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG4.BorderColor = BaseColor.Black;
            _radioG4.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;
            if (unit.ToUpper().Contains("UMUM"))
            {
                _radioG4.Checked = true;
            }
            else
            {
                _radioG4.Checked = false;
            }
            _radioG4.Rotation = 90;
            _radioG4.Options  = TextField.READ_ONLY;
            _radioField14     = _radioG4.CheckField;
            cellform4.CellEvent
                = new BebanUnitEvent(_checkGroup4, _radioField14, 1);
            headerTable3a.AddCell(cellform4);

            cellHeaderBody.Phrase = new Phrase("Umum", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            //================================================

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform5 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform5.FixedHeight = 5f;
            //initiate form checkbox
            PdfFormField    _checkGroup5 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG5;
            PdfFormField    _radioField15;
            Rectangle       kotak5 = new Rectangle(100, 100);
            _radioG5             = new RadioCheckField(writer, kotak5, "abc", "Yes");
            _radioG5.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG5.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG5.BorderColor = BaseColor.Black;
            _radioG5.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;
            if (unit.ToUpper().Contains("SPINNING 2"))
            {
                _radioG5.Checked = true;
            }
            else
            {
                _radioG5.Checked = false;
            }
            _radioG5.Rotation = 90;
            _radioG5.Options  = TextField.READ_ONLY;
            _radioField15     = _radioG5.CheckField;
            cellform5.CellEvent
                = new BebanUnitEvent(_checkGroup5, _radioField15, 1);
            headerTable3a.AddCell(cellform5);
            cellHeaderBody.Phrase = new Phrase("Spinning 2", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform6 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform6.FixedHeight = 5f;
            //initiate form checkbox
            PdfFormField    _checkGroup6 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG6;
            PdfFormField    _radioField16;
            Rectangle       kotak6 = new Rectangle(100, 100);
            _radioG6             = new RadioCheckField(writer, kotak6, "abc", "Yes");
            _radioG6.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG6.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG6.BorderColor = BaseColor.Black;
            _radioG6.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;
            if (unit.ToUpper().Contains("WEAVING 2"))
            {
                _radioG6.Checked = true;
            }
            else
            {
                _radioG6.Checked = false;
            }
            _radioG6.Rotation = 90;
            _radioG6.Options  = TextField.READ_ONLY;
            _radioField16     = _radioG6.CheckField;
            cellform6.CellEvent
                = new BebanUnitEvent(_checkGroup6, _radioField16, 1);
            headerTable3a.AddCell(cellform6);
            cellHeaderBody.Phrase = new Phrase("Weaving 2", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform7 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform7.FixedHeight = 5f;
            //initiate form checkbox
            PdfFormField    _checkGroup7 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG7;
            PdfFormField    _radioField17;
            Rectangle       kotak7 = new Rectangle(100, 100);
            _radioG7             = new RadioCheckField(writer, kotak7, "abc", "Yes");
            _radioG7.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG7.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG7.BorderColor = BaseColor.Black;
            _radioG7.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;
            if (unit.ToUpper().Contains("KONFEKSI 1A"))
            {
                _radioG7.Checked = true;
            }
            else
            {
                _radioG7.Checked = false;
            }
            _radioG7.Rotation = 90;
            _radioG7.Options  = TextField.READ_ONLY;
            _radioField17     = _radioG7.CheckField;
            cellform7.CellEvent
                = new BebanUnitEvent(_checkGroup7, _radioField17, 1);
            headerTable3a.AddCell(cellform7);
            cellHeaderBody.Phrase = new Phrase("Konfeksi 1A", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform8 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform8.FixedHeight = 5f;
            //initiate form checkbox
            PdfFormField    _checkGroup8 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG8;
            PdfFormField    _radioField18;
            Rectangle       kotak8 = new Rectangle(100, 100);
            _radioG8             = new RadioCheckField(writer, kotak8, "abc", "Yes");
            _radioG8.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG8.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG8.BorderColor = BaseColor.Black;
            _radioG8.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;
            if (unit.ToUpper().Contains("KONFEKSI 2B"))
            {
                _radioG8.Checked = true;
            }
            else
            {
                _radioG8.Checked = false;
            }
            _radioG8.Rotation = 90;
            _radioG8.Options  = TextField.READ_ONLY;
            _radioField18     = _radioG8.CheckField;
            cellform8.CellEvent
                = new BebanUnitEvent(_checkGroup8, _radioField18, 1);
            headerTable3a.AddCell(cellform8);
            cellHeaderBody.Phrase = new Phrase("Konfeksi 2 B", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform9 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform9.FixedHeight = 5f;
            //initiate form checkbox
            PdfFormField    _checkGroup9 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG9;
            PdfFormField    _radioField19;
            Rectangle       kotak9 = new Rectangle(100, 100);
            _radioG9             = new RadioCheckField(writer, kotak9, "abc", "Yes");
            _radioG9.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG9.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG9.BorderColor = BaseColor.Black;
            _radioG9.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;

            string res;
            if (lastitem.ToUpper() == "SPINNING 1" || lastitem.ToUpper() == "SPINNING 2" || lastitem.ToUpper() == "SPINNING 3" || lastitem.ToUpper() == "WEAVING 1" || lastitem.ToUpper() == "WEAVING 2" ||
                lastitem.ToUpper() == "PRINTING" || lastitem.ToUpper() == "FINISHING" || lastitem.ToUpper() == "KONFEKSI 1A" || lastitem.ToUpper() == "KONFEKSI 1B" ||
                lastitem.ToUpper() == "KONFEKSI 2A" || lastitem.ToUpper() == "KONFEKSI 2B" || lastitem.ToUpper() == "KONFEKSI 2C" || lastitem.ToUpper() == "UMUM")
            {
                _radioG9.Checked = false;
                res = ".......";
            }
            else
            {
                _radioG9.Checked = true;
                res = lastitem;
            }

            _radioG9.Rotation = 90;
            _radioG9.Options  = TextField.READ_ONLY;
            _radioField19     = _radioG9.CheckField;
            cellform9.CellEvent
                = new BebanUnitEvent(_checkGroup9, _radioField19, 1);
            headerTable3a.AddCell(cellform9);
            cellHeaderBody.Phrase = new Phrase(res, normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            //================================================

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform10 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform10.FixedHeight = 5f;
            //initiate form checkbox
            PdfFormField    _checkGroup10 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG10;
            PdfFormField    _radioField110;
            Rectangle       kotak10 = new Rectangle(100, 100);
            _radioG10             = new RadioCheckField(writer, kotak10, "abc", "Yes");
            _radioG10.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG10.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG10.BorderColor = BaseColor.Black;
            _radioG10.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;
            if (unit.ToUpper().Contains("SPINNING 3"))
            {
                _radioG10.Checked = true;
            }
            else
            {
                _radioG10.Checked = false;
            }
            _radioG10.Rotation = 90;
            _radioG10.Options  = TextField.READ_ONLY;
            _radioField110     = _radioG10.CheckField;
            cellform10.CellEvent
                = new BebanUnitEvent(_checkGroup10, _radioField110, 1);
            headerTable3a.AddCell(cellform10);
            cellHeaderBody.Phrase = new Phrase("Spinning 3", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform11 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform11.FixedHeight = 5f;
            //initiate form checkbox
            PdfFormField    _checkGroup11 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG11;
            PdfFormField    _radioField111;
            Rectangle       kotak11 = new Rectangle(100, 100);
            _radioG11             = new RadioCheckField(writer, kotak11, "abc", "Yes");
            _radioG11.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG11.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG11.BorderColor = BaseColor.Black;
            _radioG11.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;
            if (unit.ToUpper().Contains("PRINTING"))
            {
                _radioG11.Checked = true;
            }
            else
            {
                _radioG11.Checked = false;
            }
            _radioG11.Rotation = 90;
            _radioG11.Options  = TextField.READ_ONLY;
            _radioField111     = _radioG11.CheckField;
            cellform11.CellEvent
                = new BebanUnitEvent(_checkGroup11, _radioField111, 1);
            headerTable3a.AddCell(cellform11);
            cellHeaderBody.Phrase = new Phrase("Printing", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform12 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform12.FixedHeight = 5f;
            //initiate form checkbox
            PdfFormField    _checkGroup12 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG12;
            PdfFormField    _radioField112;
            Rectangle       kotak12 = new Rectangle(100, 100);
            _radioG12             = new RadioCheckField(writer, kotak12, "abc", "Yes");
            _radioG12.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG12.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG12.BorderColor = BaseColor.Black;
            _radioG12.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;
            if (unit.ToUpper().Contains("KONFEKSI 1B"))
            {
                _radioG12.Checked = true;
            }
            else
            {
                _radioG12.Checked = false;
            }
            _radioG12.Rotation = 90;
            _radioG12.Options  = TextField.READ_ONLY;
            _radioField112     = _radioG12.CheckField;
            cellform12.CellEvent
                = new BebanUnitEvent(_checkGroup12, _radioField112, 1);
            headerTable3a.AddCell(cellform12);
            cellHeaderBody.Phrase = new Phrase("Konfeksi 1B", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase("", normal_font);
            PdfPCell cellform13 = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER
            };
            cellform13.FixedHeight = 5f;
            //initiate form checkbox
            PdfFormField    _checkGroup13 = PdfFormField.CreateEmpty(writer);
            RadioCheckField _radioG13;
            PdfFormField    _radioField113;
            Rectangle       kotak13 = new Rectangle(100, 100);
            _radioG13             = new RadioCheckField(writer, kotak13, "abc", "Yes");
            _radioG13.CheckType   = RadioCheckField.TYPE_CHECK;
            _radioG13.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
            _radioG13.BorderColor = BaseColor.Black;
            _radioG13.BorderWidth = BaseField.BORDER_WIDTH_MEDIUM;
            if (unit.ToUpper().Contains("KONFEKSI 2C"))
            {
                _radioG13.Checked = true;
            }
            else
            {
                _radioG13.Checked = false;
            }
            _radioG13.Rotation = 90;
            _radioG13.Options  = TextField.READ_ONLY;
            _radioField113     = _radioG13.CheckField;
            cellform13.CellEvent
                = new BebanUnitEvent(_checkGroup13, _radioField113, 1);
            headerTable3a.AddCell(cellform13);
            cellHeaderBody.Phrase = new Phrase("Konfeksi 2C", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            headerTable3a.AddCell(cellHeaderBody);
            cellHeaderBody.Phrase = new Phrase(" ", normal_font);
            headerTable3a.AddCell(cellHeaderBody);

            cellHeader3a.AddElement(headerTable3a);
            headerTable_C.AddCell(cellHeader3a);
            document.Add(headerTable_C);
            writer.AddAnnotation(_checkGroup);
            writer.AddAnnotation(_checkGroup1);
            writer.AddAnnotation(_checkGroup2);
            writer.AddAnnotation(_checkGroup3);
            writer.AddAnnotation(_checkGroup4);
            writer.AddAnnotation(_checkGroup5);
            writer.AddAnnotation(_checkGroup6);
            writer.AddAnnotation(_checkGroup7);
            writer.AddAnnotation(_checkGroup8);
            writer.AddAnnotation(_checkGroup9);
            writer.AddAnnotation(_checkGroup10);
            writer.AddAnnotation(_checkGroup11);
            writer.AddAnnotation(_checkGroup12);
            writer.AddAnnotation(_checkGroup13);
            #endregion

            #region Footer

            PdfPTable table = new PdfPTable(4)
            {
                WidthPercentage = 100
            };
            float[] widths = new float[] { 1f, 1f, 1f, 1f };
            table.SetWidths(widths);
            PdfPCell cell = new PdfPCell()
            {
                Border = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_CENTER,
                VerticalAlignment   = Element.ALIGN_MIDDLE,
            };

            PdfPCell cellLeft = new PdfPCell()
            {
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_MIDDLE,
            };

            PdfPCell cellColspan = new PdfPCell()
            {
                Colspan             = 4,
                Border              = Rectangle.NO_BORDER,
                HorizontalAlignment = Element.ALIGN_LEFT,
                VerticalAlignment   = Element.ALIGN_MIDDLE,
            };


            cell.Phrase = new Phrase("", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("", normal_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("Menyetujui,", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("Mengetahui,", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("Diminta Oleh,", normal_font);
            table.AddCell(cell);

            for (var i = 0; i < 11; i++)
            {
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
                cell.Phrase = new Phrase("", normal_font);
                table.AddCell(cell);
            }

            cell.Phrase = new Phrase("(..................)", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("(..................)", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("(..................)", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase($"({viewModel.CreatedBy})", normal_font);
            table.AddCell(cell);

            cell.Phrase = new Phrase("Kasir", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("Anggaran", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase("..................", normal_font);
            table.AddCell(cell);
            cell.Phrase = new Phrase($"Bag. {viewModel.Unit.Name}", normal_font);
            table.AddCell(cell);

            document.Add(table);
            #endregion Footer

            document.Close();
            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;

            return(stream);
        }
Пример #13
0
        public ValueCreationBlock()
        {
            filenameBlank = filename.Replace(".", "_Blank.");

            FileStream fs = new System.IO.FileStream(filenameBlank, System.IO.FileMode.Create);

            writer = PdfWriter.GetInstance(doc, fs);
            doc.Open();
            cb = writer.DirectContent;

            BaseFont bfHelvetica = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, false);
            Font     helvetica12 = new Font(bfHelvetica, 12, Font.NORMAL, BaseColor.BLACK);

            PdfPTable table = new PdfPTable(2);

            table.TotalWidth  = 570f;
            table.LockedWidth = true;
            //relative col widths in proportions - 1/3 and 2/3
            float[] widths = new float[] { 2f, 3f };
            table.SetWidths(widths);
            table.HorizontalAlignment = Element.ALIGN_CENTER;


            PdfPCell cell1 = new PdfPCell(new Phrase("Value Creation and Impact", new Font(Font.NORMAL, 10f, Font.NORMAL, BaseColor.WHITE)));

            cell1.PaddingLeft         = 10;
            cell1.BackgroundColor     = PDFColor.BCGGreen;
            cell1.Colspan             = 3;
            cell1.Border              = PdfPCell.NO_BORDER;
            cell1.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
            table.AddCell(cell1);

            PdfPTable nested = new PdfPTable(1);
            //nested.TotalWidth = 270f;
            //nested.LockedWidth = true;
            //float[] widthforcol = new float[] { 100f, 170f};
            //nested.SetWidths(widthforcol);

            PdfPCell cell2 = new PdfPCell(new Phrase("Develops clear recommendations with an action bias", new Font(Font.NORMAL, 10f, Font.NORMAL, BaseColor.BLACK)));

            cell2.PaddingLeft = 10;
            //cell2.Colspan = 2;
            cell2.BackgroundColor     = BaseColor.LIGHT_GRAY;
            cell2.Border              = PdfPCell.NO_BORDER;
            cell2.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
            nested.AddCell(cell2);

            PdfPCell cell3 = new PdfPCell(new Phrase("Networks within client organization to understand agenda", new Font(Font.NORMAL, 10f, Font.NORMAL, BaseColor.BLACK)));

            cell3.PaddingLeft = 10;
            //cell3.Colspan = 2;
            cell3.BackgroundColor     = BaseColor.LIGHT_GRAY;
            cell3.Border              = PdfPCell.NO_BORDER;
            cell3.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
            nested.AddCell(cell3);

            PdfPCell cell4 = new PdfPCell(new Phrase("Is able to assess implementation challenges", new Font(Font.NORMAL, 10f, Font.NORMAL, BaseColor.BLACK)));

            cell4.PaddingLeft = 10;
            //cell4.Colspan = 2;
            cell4.BackgroundColor     = BaseColor.LIGHT_GRAY;
            cell4.Border              = PdfPCell.NO_BORDER;
            cell4.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
            nested.AddCell(cell4);

            PdfPCell cell5 = new PdfPCell(new Phrase("Applies expertise to generate superior and sustainable results for client; is committed to making change happen", new Font(Font.NORMAL, 10f, Font.NORMAL, BaseColor.BLACK)));

            cell5.PaddingLeft = 10;
            //cell5.Colspan = 2;
            cell5.BackgroundColor     = BaseColor.LIGHT_GRAY;
            cell5.Border              = PdfPCell.NO_BORDER;
            cell5.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
            nested.AddCell(cell5);

            PdfPCell cell6 = new PdfPCell(new Phrase("Effectively transfers capabilities to client teams", new Font(Font.NORMAL, 10f, Font.NORMAL, BaseColor.BLACK)));

            cell6.PaddingLeft = 10;
            //cell6.Colspan = 2;
            cell6.BackgroundColor     = BaseColor.LIGHT_GRAY;
            cell6.Border              = PdfPCell.NO_BORDER;
            cell6.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
            nested.AddCell(cell6);

            //Rectangle rect = new iTextSharp.text.Rectangle(10, 20, 30, 40);
            //var rf1 = new RadioCheckField(writer, rect, "cellRadioBox", "on");
            //rf1.CheckType = RadioCheckField.TYPE_CHECK;
            //PdfFormField field = rf1.CheckField;

            string[] labels = { "NA", "1", "2", "3", "4", "5" };
            BaseFont bf     = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
            // create a radio field spanning different pages
            PdfFormField radiogroup = PdfFormField.CreateRadioButton(writer, true);

            radiogroup.FieldName = "language";
            //Rectangle rect = new Rectangle(40, 606, 60, 588);
            RadioCheckField radio;
            PdfFormField    radiofield;
            Rectangle       rect;

            for (int i = 0; i < labels.Length; ++i)
            {
                rect = new Rectangle(50 + i * 30, 705, 50 + (i + 1) * 30, 695);//PDFDocPageSize.RIGHT
                //rect = new Rectangle(40, 606, 60, 588);
                radio = new RadioCheckField(writer, rect, null, labels[i]);
                radio.BackgroundColor  = new GrayColor(0.8f);
                radiofield             = radio.RadioField;
                radiofield.PlaceInPage = 1;
                //radiofield.PlaceInPage= ++page;
                radiogroup.AddKid(radiofield);
            }


            var      radioEvents = new iTextSharp.text.pdf.events.FieldPositioningEvents(writer, radiogroup);
            PdfPCell radioCell   = new PdfPCell();

            radioCell.CellEvent = radioEvents;
            nested.AddCell(radioCell);

            PdfPCell nesthousing = new PdfPCell(nested);

            nesthousing.Padding = 0f;
            table.AddCell(nesthousing);
            TextField textfield = new TextField(writer, new iTextSharp.text.Rectangle(10, 20, 30, 40), "cellTextBox");
            PdfPCell  tbCell    = new PdfPCell(new Phrase(" ", helvetica12));

            iTextSharp.text.pdf.events.FieldPositioningEvents events =
                new iTextSharp.text.pdf.events.FieldPositioningEvents(writer, textfield.GetTextField());
            tbCell.CellEvent = events;
            table.AddCell(tbCell);

            doc.Add(table);

            this.doc.Close();

            GetReader();


            //Add common Javascript code
            writer.AddJavaScript("var requiredFields = ['text1', 'grp1'];");
            string validateFunction = "function validate () { " +
                                      " for (i=0; i<requiredFields.length; i++) {" +
                                      " var grp = this.getField(requiredFields[i]);  if (!grp || grp.value === null || grp.value == ''|| grp.value=='Off') { " +
                                      " app.alert('please select this '+ requiredFields[i]); return false; }}" +
                                      "return true}";

            writer.AddJavaScript(validateFunction);


            //Close all the streams
            stamper.Close();
            reader.Close();
            doc.Close();
        }
Пример #14
0
        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            //TODO: THIS WILL BE DRIVEN BY A FORM FILLED BY THE USER TO ADD ITEMS FOR THE TEAM TO CHECK
            String[] LANGUAGES_gc = { "Scac", "Master Bill", "Comm Inv No", "Test Item", "Another" };

            System.IO.FileStream fs = new FileStream(@"C:\Users\abuchanan.LII01\Desktop\First PDF document.pdf", FileMode.Create);

            // Create an instance of the document class which represents the PDF document itself.
            Document document = new Document(PageSize.A4, 25, 25, 30, 30);
            // Create an instance to the PDF file by creating an instance of the PDF
            // Writer class using the document and the filestrem in the constructor.

            PdfWriter writer = PdfWriter.GetInstance(document, fs);

            // Add meta information to the document

            document.AddAuthor("Anthony Buchanan");

            document.AddKeywords("USeTeam EDI - Operations Team Testing Signoff");

            document.AddSubject("Document subject - Describing the steps creating a PDF document");

            document.AddTitle("The document title - PDF creation using iTextSharp");

            // Open the document to enable you to write to the document

            document.Open();
            PdfContentByte cb = writer.DirectContent;
            //TextField _text = new TextField(writer, new Rectangle(40, 806, 160, 788), "g1");
            //_text.Alignment = Element.ALIGN_LEFT;
            //_text.Options = TextField.MULTILINE;
            //_text.Text = "abc";
            //writer.AddAnnotation(_text.GetTextField());

            Rectangle    _rect;
            PdfFormField _Field1;
            PdfFormField _Field2;

            PdfAppearance[] onOff = new PdfAppearance[3];
            onOff[0] = cb.CreateAppearance(20, 20);
            onOff[0].Rectangle(1, 1, 18, 18);
            onOff[0].Stroke();

            //Pass Checkbox
            onOff[1] = cb.CreateAppearance(20, 20);
            onOff[1].SetRGBColorFill(0, 252, 0);
            onOff[1].Rectangle(1, 1, 18, 18);
            onOff[1].FillStroke();
            onOff[1].MoveTo(1, 1);
            onOff[1].LineTo(19, 19);
            onOff[1].MoveTo(1, 19);
            onOff[1].LineTo(19, 1);
            onOff[1].Stroke();

            //Fail Checkbox
            onOff[2] = cb.CreateAppearance(20, 20);
            onOff[2].SetRGBColorFill(252, 0, 0);
            onOff[2].Rectangle(1, 1, 18, 18);
            onOff[2].FillStroke();
            onOff[2].MoveTo(1, 1);
            onOff[2].LineTo(19, 19);
            onOff[2].MoveTo(1, 19);
            onOff[2].LineTo(19, 1);
            onOff[2].Stroke();

            RadioCheckField _checkbox1;
            RadioCheckField _checkbox2;

            document.Add(new Paragraph("Pass   Fail  Field Name                                  Comments"));

            //Header Line
            cb.MoveTo(20f, 807f);
            cb.LineTo(560f, 807f);
            cb.ClosePath();
            cb.Stroke();

            cb.MoveTo(20f, 791f);
            cb.LineTo(560f, 791f);
            cb.ClosePath();
            cb.Stroke();

            for (int i = 0; i < LANGUAGES_gc.Length; i++)
            {
                _rect      = new Rectangle(30, 789 - i * 20, 50, 771 - i * 20);
                _checkbox1 = new RadioCheckField(writer, _rect, LANGUAGES_gc[i], "on");
                _Field1    = _checkbox1.CheckField;
                _Field1.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
                _Field1.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", onOff[1]);
                writer.AddAnnotation(_Field1);

                _rect      = new Rectangle(60, 789 - i * 20, 80, 771 - i * 20);
                _checkbox2 = new RadioCheckField(writer, _rect, LANGUAGES_gc[i], "on");
                _Field2    = _checkbox2.CheckField;
                _Field2.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
                _Field2.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", onOff[2]);
                writer.AddAnnotation(_Field2);

                ColumnText.ShowTextAligned(cb, Element.ALIGN_LEFT, new Phrase(LANGUAGES_gc[i], new Font(Font.FontFamily.HELVETICA, 12)), 90, 775 - i * 20, 0);

                TextField _text = new TextField(writer, new Rectangle(260, 789 - i * 20, 560, 771 - i * 20), "NoteBox");
                _text.Alignment = Element.ALIGN_LEFT;
                _text.Text      = "Add Notes here.";
                _text.SetExtraMargin(5, 0);
                writer.AddAnnotation(_text.GetTextField());

                cb.MoveTo(20f, 770 - i * 20);
                cb.LineTo(560f, 770 - i * 20);
                cb.ClosePath();
                cb.Stroke();
            }

            //TODO: ADD LOGIC IN CASE THERE ARE NO ITEMS ENTERED.

            //Column Lines

            cb.MoveTo(20f, 807f);
            cb.LineTo(20f, 807 - (((LANGUAGES_gc.Length + 1) * 20) - 3));
            cb.ClosePath();
            cb.Stroke();

            cb.MoveTo(55f, 807f);
            cb.LineTo(55f, 807 - (((LANGUAGES_gc.Length + 1) * 20) - 3));
            cb.ClosePath();
            cb.Stroke();

            cb.MoveTo(85f, 807f);
            cb.LineTo(85f, 807 - (((LANGUAGES_gc.Length + 1) * 20) - 3));
            cb.ClosePath();
            cb.Stroke();

            cb.MoveTo(259f, 807f);
            cb.LineTo(259f, 807 - (((LANGUAGES_gc.Length + 1) * 20) - 3));
            cb.ClosePath();
            cb.Stroke();

            cb.MoveTo(560f, 807f);
            cb.LineTo(560f, 807 - (((LANGUAGES_gc.Length + 1) * 20) - 3));
            cb.ClosePath();
            cb.Stroke();

            cb = writer.DirectContent;

            document.Close();
            writer.Close();
            fs.Close();
        }
Пример #15
0
        public TestCreatePDF()
        {
            filenameBlank = filename.Replace(".", "_Blank.");

            FileStream fs = new System.IO.FileStream(filenameBlank, System.IO.FileMode.Create);

            writer = PdfWriter.GetInstance(doc, fs);
            doc.Open();
            cb = writer.DirectContent;
            Rectangle rect = new Rectangle(50, 700, 300, 600)
            {
                BorderWidth = .25f,
                Border      = 255
            };

            cb.Rectangle(rect);
            cb.Stroke();


            //Add text
            Font   font3  = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 1000, Font.NORMAL, BaseColor.BLACK));
            Chunk  chunk  = new Chunk("Roopesh", new Font(FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.NORMAL, BaseColor.BLUE)));
            Phrase phrase = new Phrase(chunk);

            ColumnText ctext = new ColumnText(cb);

            ctext.SetSimpleColumn(rect.Left + 5, rect.Top, rect.Right, rect.Bottom);
            ctext.SetText(phrase);
            ctext.Go();

            this.doc.Close();

            GetReader();

            //Add TextBox
            rect = new Rectangle(rect.Left, rect.Top - 100, rect.Right, rect.Bottom - 100);
            TextField tf = new TextField(writer, rect, "text1")
            {
                Alignment   = Element.ALIGN_LEFT | Element.ALIGN_TOP,
                BorderColor = BaseColor.BLACK,
                BorderStyle = PdfBorderDictionary.STYLE_SOLID,
                Text        = "TextField"
            };

            stamper.AddAnnotation(tf.GetTextField(), 1);

            //Add Radio
            rect = new Rectangle(rect.Left, rect.Top - 100, rect.Right, rect.Bottom - 25);
            PdfFormField group = PdfFormField.CreateRadioButton(writer, true);

            group.FieldName = "grp1";
            for (int i = 0; i < 5; i++)
            {
                Rectangle       radioRect  = new Rectangle(rect.Left + i * 25, rect.Top, rect.Left + (i + 1) * 25, rect.Bottom);
                RadioCheckField radioField = new RadioCheckField(writer, radioRect, "chk" + i.ToString(), i.ToString())
                {
                    BorderColor = GrayColor.BLACK,
                    CheckType   = RadioCheckField.TYPE_CIRCLE,
                    BorderStyle = PdfBorderDictionary.STYLE_SOLID
                };
                group.AddKid(radioField.RadioField);
            }
            //group.SetAdditionalActions(PdfName.E, PdfAction.JavaScript("app.alert(validate);",writer));
            stamper.AddAnnotation(group, 1);

            //Add submit button
            rect = new Rectangle(rect.Left, rect.Top - 100, rect.Right, rect.Bottom - 25);
            PushbuttonField button = new PushbuttonField(writer, rect, "postSubmit")
            {
                FontSize        = 8,
                BackgroundColor = BaseColor.LIGHT_GRAY,
                BorderColor     = GrayColor.BLACK,
                BorderWidth     = 1f,
                BorderStyle     = PdfBorderDictionary.STYLE_BEVELED,
                TextColor       = GrayColor.GREEN,
                Text            = "Submit",
                Visibility      = PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT
            };
            PdfFormField field      = button.Field;
            String       javascript = "validate();";

            field.Action = PdfAction.JavaScript(javascript, writer);

            //field.Action = PdfAction.CreateSubmitForm( @"*****@*****.**", null, PdfAction.SUBMIT_HTML_FORMAT | PdfAction.SUBMIT_INCLUDE_NO_VALUE_FIELDS);
            stamper.AddAnnotation(field, 1);
            PdfAcroForm f = new PdfAcroForm(writer);


            //Add common Javascript code
            writer.AddJavaScript("var requiredFields = ['text1', 'grp1'];");
            string validateFunction = "function validate () { " +
                                      " for (i=0; i<requiredFields.length; i++) {" +
                                      " var grp = this.getField(requiredFields[i]);  if (!grp || grp.value === null || grp.value == ''|| grp.value=='Off') { " +
                                      " app.alert('please select this '+ requiredFields[i]); return false; }}" +
                                      "return true}";

            writer.AddJavaScript(validateFunction);


            //Close all the streams
            stamper.Close();
            reader.Close();
            doc.Close();
        }