Example #1
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();
                    PdfFormField personal = PdfFormField.CreateEmpty(writer);
                    personal.FieldName = "personal";
                    PdfPTable table = new PdfPTable(3);
                    PdfPCell  cell;

                    table.AddCell("Your name:");
                    cell         = new PdfPCell();
                    cell.Colspan = 2;
                    TextField field = new TextField(writer, new Rectangle(0, 0), "name");
                    field.FontSize = 12;
                    cell.CellEvent = new ChildFieldEvent(
                        personal, field.GetTextField(), 1
                        );
                    table.AddCell(cell);
                    table.AddCell("Login:"******"loginname");
                    field.FontSize = 12;
                    cell.CellEvent = new ChildFieldEvent(
                        personal, field.GetTextField(), 1
                        );
                    table.AddCell(cell);
                    cell           = new PdfPCell();
                    field          = new TextField(writer, new Rectangle(0, 0), "password");
                    field.Options  = TextField.PASSWORD;
                    field.FontSize = 12;
                    cell.CellEvent = new ChildFieldEvent(
                        personal, field.GetTextField(), 1
                        );
                    table.AddCell(cell);
                    table.AddCell("Your motivation:");
                    cell             = new PdfPCell();
                    cell.Colspan     = 2;
                    cell.FixedHeight = 60;
                    field            = new TextField(writer, new Rectangle(0, 0), "reason");
                    field.Options    = TextField.MULTILINE;
                    field.FontSize   = 12;
                    cell.CellEvent   = new ChildFieldEvent(
                        personal, field.GetTextField(), 1
                        );
                    table.AddCell(cell);
                    document.Add(table);
                    writer.AddAnnotation(personal);
                }
                return(ms.ToArray());
            }
        }
        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(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);
        }
        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);
        }
Example #5
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();
                    PdfFormField personal = PdfFormField.CreateEmpty(writer);
                    personal.FieldName = "personal";
                    PdfPTable table = new PdfPTable(3);
                    PdfPCell  cell;

                    table.AddCell("Your name:");
                    cell         = new PdfPCell();
                    cell.Colspan = 2;
                    TextField field = new TextField(writer, new Rectangle(0, 0), "name");
                    field.FontSize = 12;
                    cell.CellEvent = new ChildFieldEvent(
                        personal, field.GetTextField(), 1
                        );
                    table.AddCell(cell);
                    table.AddCell("Login:"******"loginname");
                    field.FontSize = 12;
                    cell.CellEvent = new ChildFieldEvent(
                        personal, field.GetTextField(), 1
                        );
                    table.AddCell(cell);
                    cell           = new PdfPCell();
                    field          = new TextField(writer, new Rectangle(0, 0), "password");
                    field.Options  = TextField.PASSWORD;
                    field.FontSize = 12;
                    cell.CellEvent = new ChildFieldEvent(
                        personal, field.GetTextField(), 1
                        );
                    table.AddCell(cell);
                    table.AddCell("Your motivation:");
                    cell             = new PdfPCell();
                    cell.Colspan     = 2;
                    cell.FixedHeight = 60;
                    field            = new TextField(writer, new Rectangle(0, 0), "reason");
                    field.Options    = TextField.MULTILINE;
                    field.FontSize   = 12;
                    cell.CellEvent   = new ChildFieldEvent(
                        personal, field.GetTextField(), 1
                        );
                    table.AddCell(cell);
                    document.Add(table);
                    writer.AddAnnotation(personal);

                    PushbuttonField button1 = new PushbuttonField(
                        writer, new Rectangle(90, 660, 140, 690), "post");
                    button1.Text            = "POST";
                    button1.BackgroundColor = new GrayColor(0.7f);
                    button1.Visibility      = PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT;
                    PdfFormField submit1 = button1.Field;
                    submit1.Action = PdfAction.CreateSubmitForm(
                        "/book/request", null,
                        PdfAction.SUBMIT_HTML_FORMAT | PdfAction.SUBMIT_COORDINATES
                        );
                    writer.AddAnnotation(submit1);
                }
                return(ms.ToArray());
            }
        }