private int GetInfo(String character, PdfAcroForm form, String name) { PdfFormField field = form.GetField(name); PdfFont font = field.GetFont(); FontMetrics fontMetrics = font.GetFontProgram().GetFontMetrics(); float fontSize = field.GetFontSize(); if (fontSize == 0) { return(1000); } Rectangle rectangle = field.GetWidgets()[0].GetRectangle().ToRectangle(); // Factor here is a leading value. We calculate it by subtracting lower left corner value from // the upper right corner value of the glyph bounding box float factor = (fontMetrics.GetBbox()[3] - fontMetrics.GetBbox()[1]) / 1000f; int rows = (int)Math.Round(rectangle.GetHeight() / (fontSize * factor) + 0.5f); int columns = (int)Math.Round(rectangle.GetWidth() / font.GetWidth(character, fontSize) + 0.5f); return(rows * columns); }
public virtual void ChoiceFieldsSetValueTest() { String srcPdf = sourceFolder + "choiceFieldsWithUnnecessaryIEntries.pdf"; String outPdf = destinationFolder + "choiceFieldsSetValueTest.pdf"; String cmpPdf = sourceFolder + "cmp_choiceFieldsSetValueTest.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(srcPdf), new PdfWriter(outPdf)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, false); PdfFormField firstField = form.GetField("First"); PdfFormField secondField = form.GetField("Second"); firstField.SetValue("First"); secondField.SetValue("Second"); PdfArray indicesFirst = ((PdfChoiceFormField)firstField).GetIndices(); PdfArray indicesSecond = ((PdfChoiceFormField)secondField).GetIndices(); PdfArray expectedIndicesFirst = new PdfArray(new int[] { 1 }); PdfArray expectedIndicesSecond = new PdfArray(new int[] { 2 }); CompareTool compareTool = new CompareTool(); NUnit.Framework.Assert.IsTrue(compareTool.CompareArrays(indicesFirst, expectedIndicesFirst)); NUnit.Framework.Assert.IsTrue(compareTool.CompareArrays(indicesSecond, expectedIndicesSecond)); pdfDocument.Close(); NUnit.Framework.Assert.IsNull(compareTool.CompareByContent(outPdf, cmpPdf, destinationFolder)); }
public virtual void MultilineTextFieldRedundantSpacesAreTrimmedTest() { String filename = destinationFolder + "multilineTextFieldRedundantSpacesAreTrimmedTest.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filename)); pdfDoc.AddNewPage(); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); PdfPage page = pdfDoc.GetFirstPage(); Rectangle rect = new Rectangle(210, 490, 90, 200); PdfTextFormField field = PdfFormField.CreateMultilineText(pdfDoc, rect, "TestField", "before spaces after spaces" ); form.AddField(field, page); pdfDoc.Close(); CompareTool compareTool = new CompareTool(); String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_multilineTextFieldRedundantSpacesAreTrimmedTest.pdf" , destinationFolder, "diff_"); if (errorMessage != null) { NUnit.Framework.Assert.Fail(errorMessage); } }
public virtual void PdfA3uCheckFieldOnAppearanceTest() { String name = "pdfA3u_checkFieldOnAppearance"; String outPath = destinationFolder + name + ".pdf"; String cmpPath = cmpFolder + "cmp_" + name + ".pdf"; String diff = "diff_" + name + "_"; PdfWriter writer = new PdfWriter(outPath); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3U, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); doc.AddNewPage(); PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); PdfFormField chk = PdfFormField.CreateCheckBox(doc, new Rectangle(100, 500, 50, 50), "name", "On", PdfFormField .TYPE_CHECK, PdfAConformanceLevel.PDF_A_3U); chk.SetBorderColor(ColorConstants.BLACK); chk.SetBorderWidth(1); form.AddField(chk); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff )); }
private void AddChildToExistingParent(PdfDictionary fieldDic, ICollection <String> existingFields, IDictionary <String, PdfFormField> fieldsTo, PdfPage toPage, PdfAnnotation annot) { PdfDictionary parent = fieldDic.GetAsDictionary(PdfName.Parent); if (parent == null) { return; } PdfString parentName = parent.GetAsString(PdfName.T); if (parentName != null) { String name = parentName.ToUnicodeString(); if (existingFields.Contains(name)) { PdfArray kids = parent.GetAsArray(PdfName.Kids); foreach (PdfObject kid in kids) { if (((PdfDictionary)kid).Get(PdfName.T).Equals(fieldDic.Get(PdfName.T))) { PdfFormField kidField = PdfFormField.MakeFormField(kid, documentTo); fieldsTo.Put(kidField.GetFieldName().ToUnicodeString(), kidField); PdfFormField mergedField = MergeFieldsWithTheSameName(PdfFormField.MakeFormField(fieldDic, documentTo)); formTo.GetFormFields().Put(mergedField.GetFieldName().ToUnicodeString(), mergedField); return; } } kids.Add(fieldDic); } else { parent.Put(PdfName.Kids, new PdfArray(fieldDic)); AddChildToExistingParent(parent, existingFields); } } }
private void CopyField(PdfPage toPage, IDictionary <String, PdfFormField> fieldsFrom, IDictionary <String, PdfFormField > fieldsTo, PdfAnnotation currentAnnot) { PdfDictionary parent = currentAnnot.GetPdfObject().GetAsDictionary(PdfName.Parent); if (parent != null) { PdfFormField parentField = GetParentField(parent, documentTo); PdfString parentName = parentField.GetFieldName(); if (parentName == null) { return; } CopyParentFormField(toPage, fieldsTo, currentAnnot, parentField); } else { PdfString annotName = currentAnnot.GetPdfObject().GetAsString(PdfName.T); String annotNameString = null; if (annotName != null) { annotNameString = annotName.ToUnicodeString(); } if (annotNameString != null && fieldsFrom.ContainsKey(annotNameString)) { PdfFormField field = fieldsTo.Get(annotNameString); if (field == null) { formTo.AddField(PdfFormField.MakeFormField(currentAnnot.GetPdfObject(), documentTo), null); } else { CopyExistingField(toPage, currentAnnot); } } } }
// --------------------------------------------------------------------------- /** * Manipulates a PDF file src with the file dest as result * @param src the original PDF */ public byte[] ManipulatePdf(byte[] src) { // create a reader PdfReader reader = new PdfReader(src); using (MemoryStream ms = new MemoryStream()) { // create a stamper using (PdfStamper stamper = new PdfStamper(reader, ms)) { // Add an open action PdfWriter writer = stamper.Writer; PdfAction action = PdfAction.JavaScript( Utilities.ReadFileToString( Path.Combine(Utility.ResourceJavaScript, "post_from_html.js") ), writer ); writer.SetOpenAction(action); // create a submit button that posts data to the HTML page PushbuttonField button1 = new PushbuttonField( stamper.Writer, new Rectangle(90, 660, 160, 690), "post" ); button1.Text = "POST TO HTML"; button1.BackgroundColor = new GrayColor(0.7f); button1.Visibility = PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT; PdfFormField submit1 = button1.Field; submit1.Action = PdfAction.JavaScript( Utilities.ReadFileToString(Path.Combine( Utility.ResourceJavaScript, "post_to_html.js" )), writer ); // add the button stamper.AddAnnotation(submit1, 1); } return(ms.ToArray()); } }
public virtual void CreatePDF(String dest) { // Create a pdf document along with a Document (default root layout element) instance PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest)); Document document = new Document(pdfDocument); // తెలుగు గుణింతాలు String fieldValue = "\u0C24\u0C46\u0C32\u0C41\u0C17\u0C41\u0020\u0C17\u0C41\u0C23\u0C3F\u0C02\u0C24\u0C3E\u0C32\u0C41"; String fieldName = "Field name"; PdfAcroForm form = PdfAcroForm.GetAcroForm(document.GetPdfDocument(), true); PdfFont font = PdfFontFactory.CreateFont(FONTS_FOLDER + "NotoSansTelugu-Regular.ttf", PdfEncodings.IDENTITY_H); // Embed entire font without any subsetting. Please note that without subset it's impossible to edit a form field // with the predefined font font.SetSubset(false); // Create a form field and set some of the properties PdfFormField formField = PdfTextFormField.CreateText(document.GetPdfDocument(), new Rectangle(50, 750, 160, 25)); formField .SetValue(fieldValue) .SetBorderWidth(2) .SetFont(font) .SetFontSize(10) .SetJustification(1) .SetFieldName(fieldName); form.AddField(formField); document.Close(); }
/* (non-Javadoc) * @see com.itextpdf.html2pdf.attach.impl.layout.form.renderer.AbstractFormFieldRenderer#applyAcroField(com.itextpdf.layout.renderer.DrawContext) */ protected internal override void ApplyAcroField(DrawContext drawContext) { font.SetSubset(false); String value = GetDefaultValue(); String name = GetModelId(); UnitValue fontSize = (UnitValue)this.GetPropertyAsUnitValue(Property.FONT_SIZE); if (!fontSize.IsPointValue()) { ILog logger = LogManager.GetLogger(typeof(iText.Html2pdf.Attach.Impl.Layout.Form.Renderer.InputFieldRenderer )); logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property .FONT_SIZE)); } PdfDocument doc = drawContext.GetDocument(); Rectangle area = flatRenderer.GetOccupiedArea().GetBBox().Clone(); PdfPage page = doc.GetPage(occupiedArea.GetPageNumber()); bool password = IsPassword(); if (password) { value = ""; } PdfFormField inputField = PdfFormField.CreateText(doc, area, name, value, font, fontSize.GetValue()); if (password) { inputField.SetFieldFlag(PdfFormField.FF_PASSWORD, true); } else { inputField.SetDefaultValue(new PdfString(value)); } ApplyDefaultFieldProperties(inputField); PdfAcroForm.GetAcroForm(doc, true).AddField(inputField, page); WriteAcroFormFieldLangAttribute(doc); }
public virtual void GetFieldsForFlatteningTest() { String outPdfName = destinationFolder + "flattenedFormField.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfReader(sourceFolder + "formFieldFile.pdf"), new PdfWriter(outPdfName )); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, false); NUnit.Framework.Assert.AreEqual(0, form.GetFieldsForFlattening().Count); form.PartialFormFlattening("radioName"); form.PartialFormFlattening("Text1"); PdfFormField radioNameField = form.GetField("radioName"); PdfFormField text1Field = form.GetField("Text1"); NUnit.Framework.Assert.AreEqual(2, form.GetFieldsForFlattening().Count); NUnit.Framework.Assert.IsTrue(form.GetFieldsForFlattening().Contains(radioNameField)); NUnit.Framework.Assert.IsTrue(form.GetFieldsForFlattening().Contains(text1Field)); form.FlattenFields(); pdfDoc.Close(); PdfDocument outPdfDoc = new PdfDocument(new PdfReader(outPdfName)); PdfAcroForm outPdfForm = PdfAcroForm.GetAcroForm(outPdfDoc, false); NUnit.Framework.Assert.AreEqual(2, outPdfForm.GetFormFields().Count); outPdfDoc.Close(); }
//Function the start of creating time sheets. //userInfo user - Info about the selected user //List<userAppointment> appLog - App. Log of user //DateTime startD - The first day of said month //DateTime endD - The last day of said month //1. Gets the selected users appointments for that month which is selected. //2. Calls fillUserHours(); - Pass DB Connect, User Object, User Appointments for the month, CoverFields of coversheet, and the out object to write to Coversheet. //3. Calls calcTotlas() - Calcs total for each budget. public virtual void createTimeSheet(userInfo user, List <userAppointment> appLog, DateTime startD, DateTime endD) { folderList = getFolderList(user); settings.Load(ref settings); //This is all for filling out the cover sheet. if (checkAvailability(user, appLog) == true) { PdfFormField toSet = null; PdfDocument pdfCover = new PdfDocument(new PdfReader(srcCover), new PdfWriter(folderList[1] + (user.lastName + ", " + user.firstName + " - " + startD.ToString("MMMM yyyy") + " Budget Cover" + ".pdf"))); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfCover, false); IDictionary <string, PdfFormField> coverFields = form.GetFormFields(); appLog = appLog.OrderBy(x => x.appointmentDate).ToList(); fillTimeSheetCoverPG(coverFields, user); calcHoursForDay(user, appLog, startD, endD, coverFields, toSet); calcTotals(user, startD, endD, coverFields, toSet); pdfCover.Close(); } else { if (user.userType.Contains("D") || user.userType.Contains("SE")) { MessageBox.Show($"User: {user.fullnameWComma()}, {user.userID} doesn't have enough hours left to be paid with.", "No Availability", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (user.userType.Contains("SWF")) { MessageBox.Show($"User: {user.fullnameWComma()}, {user.userID} doesn't have enough FWS funds to be paid with.", "No Availability", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public virtual void PdfA1bButtonAppearanceRegenerateTest() { String name = "pdfA1b_ButtonAppearanceRegenerateTest"; String outPath = destinationFolder + name + ".pdf"; String cmpPath = cmpFolder + "cmp_" + name + ".pdf"; String diff = "diff_" + name + "_"; PdfWriter writer = new PdfWriter(outPath); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1" , @is); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent); doc.SetTagged(); doc.GetCatalog().SetLang(new PdfString("en-US")); doc.AddNewPage(); PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); Rectangle rect = new Rectangle(36, 626, 100, 40); PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true); PdfFormField button = PdfFormField.CreatePushButton(doc, rect, "push button", "push", font, 12, PdfAConformanceLevel .PDF_A_1B); button.RegenerateField(); form.AddField(button); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff )); }
public override void Draw(DrawContext context) { int pageNumber = GetOccupiedArea().GetPageNumber(); Rectangle bbox = GetInnerAreaBBox(); PdfDocument pdf = context.GetDocument(); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true); PdfFormField chk = PdfFormField.CreateRadioButton(pdf, bbox, _group, _value, PdfAConformanceLevel.PDF_A_1B ); chk.SetPage(pageNumber); chk.SetVisibility(PdfFormField.VISIBLE); chk.SetBorderColor(ColorConstants.BLACK); chk.SetBackgroundColor(ColorConstants.WHITE); chk.SetReadOnly(true); PdfFormXObject appearance = new PdfFormXObject(bbox); PdfCanvas canvas = new PdfCanvas(appearance, pdf); canvas.SaveState().MoveTo(bbox.GetLeft(), bbox.GetBottom()).LineTo(bbox.GetRight(), bbox.GetBottom()).LineTo (bbox.GetRight(), bbox.GetTop()).LineTo(bbox.GetLeft(), bbox.GetTop()).LineTo(bbox.GetLeft(), bbox.GetBottom ()).SetLineWidth(1f).Stroke().RestoreState(); form.AddFieldAppearanceToPage(chk, pdf.GetPage(pageNumber)); //appearance stream was set, while AS has kept as is, i.e. in Off state. chk.SetAppearance(PdfName.N, "v1".Equals(_value) ? _value : "Off", appearance.GetPdfObject()); }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest)); PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); IDictionary <String, PdfFormField> fields = form.GetFormFields(); PdfFormField field = fields["personal.name"]; field.SetJustification(PdfFormField.ALIGN_LEFT); field.SetValue("Test"); field = fields["personal.loginname"]; field.SetJustification(PdfFormField.ALIGN_CENTER); field.SetValue("Test"); field = fields["personal.password"]; field.SetJustification(PdfFormField.ALIGN_RIGHT); field.SetValue("Test"); field = fields["personal.reason"]; field.SetValue("Test"); pdfDoc.Close(); }
public virtual void FormFieldBordersTest() { String outPdf = destinationFolder + "formFieldBorders.pdf"; String cmpPdf = sourceFolder + "cmp_formFieldBorders.pdf"; using (PdfDocument doc = new PdfDocument(new PdfWriter(outPdf))) { PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true); PdfFormField simpleField = PdfTextFormField.CreateText(doc, new Rectangle(300, 300, 200, 100), "simpleField" ); simpleField.RegenerateField(); PdfFormField insetField = PdfTextFormField.CreateText(doc, new Rectangle(50, 600, 200, 100), "insetField"); insetField.GetWidgets()[0].SetBorderStyle(PdfName.I); insetField.SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField(); PdfFormField underlineField = PdfTextFormField.CreateText(doc, new Rectangle(300, 600, 200, 100), "underlineField" ); underlineField.GetWidgets()[0].SetBorderStyle(PdfName.U); underlineField.SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField(); PdfFormField solidField = PdfTextFormField.CreateText(doc, new Rectangle(50, 450, 200, 100), "solidField"); solidField.GetWidgets()[0].SetBorderStyle(PdfName.S); solidField.SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField(); PdfFormField dashField = PdfTextFormField.CreateText(doc, new Rectangle(300, 450, 200, 100), "dashField"); dashField.GetWidgets()[0].SetBorderStyle(PdfName.D); dashField.SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField(); PdfFormField beveledField = PdfTextFormField.CreateText(doc, new Rectangle(50, 300, 200, 100), "beveledField" ); beveledField.GetWidgets()[0].SetBorderStyle(PdfName.B); beveledField.SetBorderWidth(3f).SetBorderColor(DeviceRgb.RED).RegenerateField(); form.AddField(simpleField); form.AddField(insetField); form.AddField(underlineField); form.AddField(solidField); form.AddField(dashField); form.AddField(beveledField); } NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder)); }
// --------------------------------------------------------------------------- /** * Show keys and values passed to the query string with GET */ protected void DoGet(byte[] pdf, Stream stream) { // We get a resource from our web app PdfReader reader = new PdfReader(pdf); // Now we create the PDF using (PdfStamper stamper = new PdfStamper(reader, stream)) { // We add a submit button to the existing form PushbuttonField button = new PushbuttonField( stamper.Writer, new Rectangle(90, 660, 140, 690), "submit" ); button.Text = "POST"; button.BackgroundColor = new GrayColor(0.7f); button.Visibility = PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT; PdfFormField submit = button.Field; submit.Action = PdfAction.CreateSubmitForm( WebContext.Request.RawUrl, null, 0 ); stamper.AddAnnotation(submit, 1); // We add an extra field that can be used to upload a file TextField file = new TextField( stamper.Writer, new Rectangle(160, 660, 470, 690), "image" ); file.Options = TextField.FILE_SELECTION; file.BackgroundColor = new GrayColor(0.9f); PdfFormField upload = file.GetTextField(); upload.SetAdditionalActions(PdfName.U, PdfAction.JavaScript( "this.getField('image').browseForFileToSubmit();" + "this.getField('submit').setFocus();", stamper.Writer ) ); stamper.AddAnnotation(upload, 1); } }
public void CellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) { PdfWriter writer = canvases[0].PdfWriter; TextField text = new TextField(writer, rectangle, _fieldName); switch (!_fieldName.EndsWith(AUTO_SIZE_FIELD.ToString())) { case true: text.FontSize = DEFAULT_SIZE; text.Font = _defaultFont; break; default: text.FontSize = 0; text.Font = BaseFont.CreateFont( COURIER_OBLIQUE, BaseFont.WINANSI, false ); break; } PdfFormField field = text.GetTextField(); writer.AddAnnotation(field); }
public void SetValue(string key, string value) { PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true); var i = form.GetDefaultAppearance(); var i2 = form.GetDefaultJustification(); var i3 = form.GetDefaultResources(); PdfFormField field = form.GetFormFields()[key]; if (field is PdfTextFormField) { PdfTextFormField pdfTextFormField = (PdfTextFormField)field; ///pdfTextFormField.SetDefaultAppearance("/Titillium 6 Tf 0 g"); if (pdfTextFormField.GetFieldName().GetValue().Contains("Beurteilung")) { pdfTextFormField.SetDefaultAppearance("/Helv 6 Tf 0 g"); } pdfTextFormField.SetValue(value); } else { field.SetValue(value); } }
/// <summary>Gets the field names that have blank signatures.</summary> /// <returns>List containing the field names that have blank signatures</returns> public virtual IList <String> GetBlankSignatureNames() { GetSignatureNames(); IList <String> sigs = new List <String>(); if (acroForm != null) { foreach (KeyValuePair <String, PdfFormField> entry in acroForm.GetFormFields()) { PdfFormField field = entry.Value; PdfDictionary merged = field.GetPdfObject(); if (!PdfName.Sig.Equals(merged.GetAsName(PdfName.FT))) { continue; } if (sigNames.ContainsKey(entry.Key)) { continue; } sigs.Add(entry.Key); } } return(sigs); }
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); }
public void AddCalculationOrder(PdfFormField formField) { acroForm.AddCalculationOrder(formField); }
public PdfArray RotateAnnotations(PdfWriter writer, Rectangle pageSize) { PdfArray array = new PdfArray(); int rotation = pageSize.Rotation % 360; int currentPage = writer.CurrentPageNumber; for (int k = 0; k < annotations.Count; ++k) { PdfAnnotation dic = annotations[k]; int page = dic.PlaceInPage; if (page > currentPage) { delayedAnnotations.Add(dic); continue; } if (dic.IsForm()) { if (!dic.IsUsed()) { Dictionary <PdfTemplate, object> templates = dic.Templates; if (templates != null) { acroForm.AddFieldTemplates(templates); } } PdfFormField field = (PdfFormField)dic; if (field.Parent == null) { acroForm.AddDocumentField(field.IndirectReference); } } if (dic.IsAnnotation()) { array.Add(dic.IndirectReference); if (!dic.IsUsed()) { PdfArray tmp = dic.GetAsArray(PdfName.RECT); PdfRectangle rect; if (tmp.Size == 4) { rect = new PdfRectangle(tmp.GetAsNumber(0).FloatValue, tmp.GetAsNumber(1).FloatValue, tmp.GetAsNumber(2).FloatValue, tmp.GetAsNumber(3).FloatValue); } else { rect = new PdfRectangle(tmp.GetAsNumber(0).FloatValue, tmp.GetAsNumber(1).FloatValue); } if (rect != null) { switch (rotation) { case 90: dic.Put(PdfName.RECT, new PdfRectangle( pageSize.Top - rect.Bottom, rect.Left, pageSize.Top - rect.Top, rect.Right)); break; case 180: dic.Put(PdfName.RECT, new PdfRectangle( pageSize.Right - rect.Left, pageSize.Top - rect.Bottom, pageSize.Right - rect.Right, pageSize.Top - rect.Top)); break; case 270: dic.Put(PdfName.RECT, new PdfRectangle( rect.Bottom, pageSize.Right - rect.Left, rect.Top, pageSize.Right - rect.Right)); break; } } } } if (!dic.IsUsed()) { dic.SetUsed(); writer.AddToBody(dic, dic.IndirectReference); } } return(array); }
/** Creates a new event. This constructor will be used if you need to position fields with a Cell Event. */ public FieldPositioningEvents(PdfWriter writer, PdfFormField field) { this.cellField = field; this.fieldWriter = writer; }
/** * Add a PdfFormField that has to be tied to a generic Chunk. */ public void AddField(String text, PdfFormField field) { genericChunkFields[text] = field; }
/** Creates a new event. This constructor will be used if you need to position fields with a Cell Event. */ public FieldPositioningEvents(PdfFormField parent, PdfFormField field) { this.cellField = field; this.parent = parent; }
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 ActionResult CreatePdf(IFormCollection collection) { string pdfFileWithForm = m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Pdf\PdfWithForm.pdf"; // load the PDF document with form from file PdfDocument document = PdfDocument.FromFile(pdfFileWithForm); // set a demo serial number document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ=="; // get the Check Box field by name from form fields collection and set its value PdfFormField checkBoxField = document.Form.Fields["cb"]; if (checkBoxField != null) { checkBoxField.Value = collection["checkBoxChecked"].Count > 0; } // get the Text Box field by name from form fields collection and set its value PdfFormField textBoxField = document.Form.Fields["tb"]; if (textBoxField != null) { textBoxField.Value = collection["textBoxText"][0]; } // get the List Box field by name from form fields collection and set its value PdfFormField listBoxField = document.Form.Fields["lb"]; if (listBoxField != null) { listBoxField.Value = collection["dropDownListListBoxValue"][0]; } // get the Combo Box field by name from form fields collection and set its value PdfFormField comboBoxField = document.Form.Fields["combo"]; if (comboBoxField != null) { comboBoxField.Value = collection["dropDownListComboBoxValue"][0]; } // get the Radio Buttons Group field by name from form fields collection and set its value PdfFormField radioGroupField = document.Form.Fields["rg"]; if (radioGroupField != null) { radioGroupField.Value = collection["SelectedRadionButton"] == "radioButton1" ? "rb1" : "rb2"; } try { // write the PDF document to a memory buffer byte[] pdfBuffer = document.WriteToMemory(); FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf"); fileResult.FileDownloadName = "FillForms.pdf"; return(fileResult); } finally { document.Close(); } }
private void PopulateSignatureNames() { if (acroForm == null) { return; } IList <Object[]> sorter = new List <Object[]>(); foreach (KeyValuePair <String, PdfFormField> entry in acroForm.GetFormFields()) { PdfFormField field = entry.Value; PdfDictionary merged = field.GetPdfObject(); if (!PdfName.Sig.Equals(merged.Get(PdfName.FT))) { continue; } PdfDictionary v = merged.GetAsDictionary(PdfName.V); if (v == null) { continue; } PdfString contents = v.GetAsString(PdfName.Contents); if (contents == null) { continue; } else { contents.MarkAsUnencryptedObject(); } PdfArray ro = v.GetAsArray(PdfName.ByteRange); if (ro == null) { continue; } int rangeSize = ro.Size(); if (rangeSize < 2) { continue; } int length = ro.GetAsNumber(rangeSize - 1).IntValue() + ro.GetAsNumber(rangeSize - 2).IntValue(); sorter.Add(new Object[] { entry.Key, new int[] { length, 0 } }); } JavaCollectionsUtil.Sort(sorter, new SignatureUtil.SorterComparator()); if (sorter.Count > 0) { try { if (((int[])sorter[sorter.Count - 1][1])[0] == document.GetReader().GetFileLength()) { totalRevisions = sorter.Count; } else { totalRevisions = sorter.Count + 1; } } catch (System.IO.IOException) { } // TODO: add exception handling (at least some logger) for (int k = 0; k < sorter.Count; ++k) { Object[] objs = sorter[k]; String name = (String)objs[0]; int[] p = (int[])objs[1]; p[1] = k + 1; sigNames.Put(name, p); orderedSignatureNames.Add(name); } } }
public Chap13_form() { Console.WriteLine("Chapter 13: a form with some text"); // step 1: creation of a document-object Document document = new Document(PageSize.A4, 50, 50, 50, 50); try { // step 2: we create a writer that listens to the document PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap13_form.pdf", FileMode.Create)); PdfAcroForm acroForm = writer.AcroForm; // step 3: we open the document document.Open(); // step 4: we add some content BaseFont helv = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); float fontSize = 12; acroForm.AddSingleLineTextField("name", "your name", helv, fontSize, 171, 800, 350, 820); acroForm.AddMultiLineTextField("msg", "Hello iText!\nThis is a Test\nThere are multiple lines in this textfield", helv, fontSize, 171, 730, 350, 790); acroForm.AddSingleLinePasswordField("password", "", helv, fontSize, 171, 700, 350, 720); acroForm.AddHtmlPostButton("btn", "SUBMIT", "noValue", "Chap13.php", helv, fontSize, 355, 700, 420, 725); acroForm.AddResetButton("reset", "RESET", null, helv, fontSize, 430, 700, 495, 725); acroForm.AddCheckBox("CB1", "Food", true, 180, 685, 190, 695); acroForm.AddCheckBox("CB2", "Drinks", false, 180, 645, 210, 675); PdfFormField radiogroup = acroForm.GetRadioGroup("CreditCard", "Visa", true); acroForm.AddRadioButton(radiogroup, "Visa", 180, 625, 195, 640); acroForm.AddRadioButton(radiogroup, "MasterCard", 200, 625, 215, 640); acroForm.AddRadioButton(radiogroup, "American", 220, 625, 235, 640); acroForm.AddRadioGroup(radiogroup); String[] colors = { "Red", "Green", "Blue" }; String[,] colorvalues = { { "#FF0000", "Red" }, { "#00FF00", "Green" }, { "#0000FF", "Blue" } }; acroForm.AddSelectList("list1", colors, "Green", helv, fontSize, 171, 550, 300, 600); acroForm.AddSelectList("list2", colorvalues, "#0000FF", helv, fontSize, 315, 550, 450, 600); acroForm.AddComboBox("combo1", colors, "Green", true, helv, fontSize, 171, 440, 300, 490); acroForm.AddComboBox("combo2", colorvalues, "#0000FE", false, helv, fontSize, 315, 440, 450, 490); PdfContentByte cb = new PdfContentByte(null); cb.SetRGBColorStroke(0x00, 0x00, 0x00); cb.SetRGBColorFill(0xFF, 0x00, 0x00); cb.Arc(0, 0, 100, 100, 0, 360); cb.FillStroke(); cb.SetRGBColorStroke(0x00, 0x00, 0x00); cb.SetRGBColorFill(0xFF, 0xFF, 0xFF); cb.Arc(20, 20, 80, 80, 0, 360); cb.FillStroke(); cb.SetRGBColorStroke(0x00, 0x00, 0x00); cb.SetRGBColorFill(0xFF, 0x00, 0x00); cb.Arc(40, 40, 60, 60, 0, 360); cb.FillStroke(); cb.SetRGBColorFill(0x00, 0x00, 0x00); cb.Arc(48, 48, 52, 52, 0, 360); cb.Fill(); acroForm.AddMap("map", null, "Chap13.php", cb, 171, 300, 271, 400); acroForm.AddHiddenField("hidden", "secret"); } catch (DocumentException de) { Console.Error.WriteLine(de.Message); } catch (IOException ioe) { Console.Error.WriteLine(ioe.Message); } // step 5: close the document document.Close(); }