Skip to content

Commit

Permalink
Formats
Browse files Browse the repository at this point in the history
  • Loading branch information
KhromovNikita committed Feb 18, 2025
1 parent 5269fc7 commit 7e393e8
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 26 deletions.
142 changes: 135 additions & 7 deletions pdf/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,127 @@
}
}, AscDFH.historydescription_Pdf_AddField, this);
};
PDFEditorApi.prototype.SetFieldNumberFormat = function(nDemical, nSepStyle, nNegStyle, sCurrency, bCurrencyPrepend) {
let oDoc = this.getPDFDoc();

oDoc.DoAction(function() {
let oField = oDoc.activeForm;

let oActionsFormat = [{
"S": AscPDF.ACTIONS_TYPES.JavaScript,
"JS": "AFNumber_Format(" + nDemical + "," + nSepStyle + "," + nNegStyle + "," + "0" + "," + sCurrency + "," + bCurrencyPrepend + ");"
}];
oField.SetActions(AscPDF.FORMS_TRIGGERS_TYPES.Format, oActionsFormat);

let oActionsKeystroke = [{
"S": AscPDF.ACTIONS_TYPES.JavaScript,
"JS": "AFNumber_Keystroke(" + nDemical + "," + nSepStyle + "," + nNegStyle + "," + "0" + "," + sCurrency + "," + bCurrencyPrepend + ");"
}];
oField.SetActions(AscPDF.FORMS_TRIGGERS_TYPES.Keystroke, oActionsKeystroke);

}, AscDFH.historydescription_Pdf_AddField, this);
};
PDFEditorApi.prototype.SetFieldPercentageFormat = function(nDemical, nSepStyle) {
let oDoc = this.getPDFDoc();

oDoc.DoAction(function() {
let oField = oDoc.activeForm;

let oActionsFormat = [{
"S": AscPDF.ACTIONS_TYPES.JavaScript,
"JS": "AFPercent_Format(" + nDemical + "," + nSepStyle + ");"
}]
oField.SetActions(AscPDF.FORMS_TRIGGERS_TYPES.Format, oActionsFormat);

let oActionsKeystroke = [{
"S": AscPDF.ACTIONS_TYPES.JavaScript,
"JS": "AFPercent_Keystroke(" + nDemical + "," + nSepStyle + ");"
}];
oField.SetActions(AscPDF.FORMS_TRIGGERS_TYPES.Keystroke, oActionsKeystroke);

}, AscDFH.historydescription_Pdf_AddField, this);
};

PDFEditorApi.prototype.SetFieldDateFormat = function(sFormat) {
let oDoc = this.getPDFDoc();

oDoc.DoAction(function() {
let oField = oDoc.activeForm;

let oActionsFormat = [{
"S": AscPDF.ACTIONS_TYPES.JavaScript,
"JS": "AFDate_Format(" + sFormat + ");"
}]
oField.SetActions(AscPDF.FORMS_TRIGGERS_TYPES.Format, oActionsFormat);

let oActionsKeystroke = [{
"S": AscPDF.ACTIONS_TYPES.JavaScript,
"JS": "AFDate_Keystroke(" + sFormat + ");"
}];
oField.SetActions(AscPDF.FORMS_TRIGGERS_TYPES.Keystroke, oActionsKeystroke);

}, AscDFH.historydescription_Pdf_AddField, this);
};

PDFEditorApi.prototype.SetFieldTimeFormat = function(sFormat) {
let oDoc = this.getPDFDoc();

oDoc.DoAction(function() {
let oField = oDoc.activeForm;

let oActionsFormat = [{
"S": AscPDF.ACTIONS_TYPES.JavaScript,
"JS": "AFTime_Format(" + sFormat + ");"
}]
oField.SetActions(AscPDF.FORMS_TRIGGERS_TYPES.Format, oActionsFormat);

let oActionsKeystroke = [{
"S": AscPDF.ACTIONS_TYPES.JavaScript,
"JS": "AFTime_Keystroke(" + sFormat + ");"
}];
oField.SetActions(AscPDF.FORMS_TRIGGERS_TYPES.Keystroke, oActionsKeystroke);

}, AscDFH.historydescription_Pdf_AddField, this);
};

PDFEditorApi.prototype.SetFieldSpecialFormat = function(sFormat) {
let oDoc = this.getPDFDoc();

oDoc.DoAction(function() {
let oField = oDoc.activeForm;

let oActionsFormat = [{
"S": AscPDF.ACTIONS_TYPES.JavaScript,
"JS": "AFSpecial_Format(" + sFormat + ");"
}]
oField.SetActions(AscPDF.FORMS_TRIGGERS_TYPES.Format, oActionsFormat);

let oActionsKeystroke = [{
"S": AscPDF.ACTIONS_TYPES.JavaScript,
"JS": "AFSpecial_Keystroke(" + sFormat + ");"
}];
oField.SetActions(AscPDF.FORMS_TRIGGERS_TYPES.Keystroke, oActionsKeystroke);

}, AscDFH.historydescription_Pdf_AddField, this);
};

PDFEditorApi.prototype.SetFieldMask = function(sMask) {
let oDoc = this.getPDFDoc();

oDoc.DoAction(function() {
let oField = oDoc.activeForm;

let oActionsFormat = []
oField.SetActions(AscPDF.FORMS_TRIGGERS_TYPES.Format, oActionsFormat);

let oActionsKeystroke = [{
"S": AscPDF.ACTIONS_TYPES.JavaScript,
"JS": "AFSpecial_KeystrokeEx(" + sMask + ");"
}];
oField.SetActions(AscPDF.FORMS_TRIGGERS_TYPES.Keystroke, oActionsKeystroke);

}, AscDFH.historydescription_Pdf_AddField, this);
};
/////////////////////////////////////////////////////////////
///////// For drawings
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3204,13 +3325,20 @@
PDFEditorApi.prototype['AddFreeTextAnnot'] = PDFEditorApi.prototype.AddFreeTextAnnot;

// forms
PDFEditorApi.prototype['AddTextField'] = PDFEditorApi.prototype.AddTextField;
PDFEditorApi.prototype['AddDateField'] = PDFEditorApi.prototype.AddDateField;
PDFEditorApi.prototype['AddImageField'] = PDFEditorApi.prototype.AddImageField;
PDFEditorApi.prototype['AddCheckboxField'] = PDFEditorApi.prototype.AddCheckboxField;
PDFEditorApi.prototype['AddRadiobuttonField'] = PDFEditorApi.prototype.AddRadiobuttonField;
PDFEditorApi.prototype['AddComboboxField'] = PDFEditorApi.prototype.AddComboboxField;
PDFEditorApi.prototype['AddListboxField'] = PDFEditorApi.prototype.AddListboxField;
PDFEditorApi.prototype['AddTextField'] = PDFEditorApi.prototype.AddTextField;
PDFEditorApi.prototype['AddDateField'] = PDFEditorApi.prototype.AddDateField;
PDFEditorApi.prototype['AddImageField'] = PDFEditorApi.prototype.AddImageField;
PDFEditorApi.prototype['AddCheckboxField'] = PDFEditorApi.prototype.AddCheckboxField;
PDFEditorApi.prototype['AddRadiobuttonField'] = PDFEditorApi.prototype.AddRadiobuttonField;
PDFEditorApi.prototype['AddComboboxField'] = PDFEditorApi.prototype.AddComboboxField;
PDFEditorApi.prototype['AddListboxField'] = PDFEditorApi.prototype.AddListboxField;
PDFEditorApi.prototype['AddListFieldOption'] = PDFEditorApi.prototype.AddListFieldOption;
PDFEditorApi.prototype['SetFieldNumberFormat'] = PDFEditorApi.prototype.SetFieldNumberFormat;
PDFEditorApi.prototype['SetFieldPercentageFormat'] = PDFEditorApi.prototype.SetFieldPercentageFormat;
PDFEditorApi.prototype['SetFieldDateFormat'] = PDFEditorApi.prototype.SetFieldDateFormat;
PDFEditorApi.prototype['SetFieldTimeFormat'] = PDFEditorApi.prototype.SetFieldTimeFormat;
PDFEditorApi.prototype['SetFieldSpecialFormat'] = PDFEditorApi.prototype.SetFieldSpecialFormat;
PDFEditorApi.prototype['SetFieldMask'] = PDFEditorApi.prototype.SetFieldMask;

// drawings
PDFEditorApi.prototype['AddTextArt'] = PDFEditorApi.prototype.AddTextArt;
Expand Down
82 changes: 63 additions & 19 deletions pdf/src/forms/apiFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,46 @@
*
*/

(function(){
(function() {

const FormattingType = {
ZIP_CODE: 0, // Почтовый индекс (ZIP Code)
ZIP_PLUS_4: 1, // Почтовый индекс + 4 (ZIP + 4)
PHONE: 2, // Телефонный номер
SSN: 3 // Социальное страхование (SSN)
}

FormattingType["ZIP_CODE"] = FormattingType.ZIP_CODE;
FormattingType["ZIP_PLUS_4"] = FormattingType.ZIP_PLUS_4;
FormattingType["PHONE"] = FormattingType.PHONE;
FormattingType["SSN"] = FormattingType.SSN;

const SeparatorStyle = {
COMMA_DOT: 0, // 1,234.56
NO_SEPARATOR: 1, // 1234.56
DOT_COMMA: 2, // 1.234,56
NO_SEPARATOR_COMMA: 3, // 1234,56
APOSTROPHE_DOT: 4 // 1'234.56
};

SeparatorStyle["COMMA_DOT"] = SeparatorStyle.COMMA_DOT;
SeparatorStyle["NO_SEPARATOR"] = SeparatorStyle.NO_SEPARATOR;
SeparatorStyle["DOT_COMMA"] = SeparatorStyle.DOT_COMMA;
SeparatorStyle["NO_SEPARATOR_COMMA"] = SeparatorStyle.NO_SEPARATOR_COMMA;
SeparatorStyle["APOSTROPHE_DOT"] = SeparatorStyle.APOSTROPHE_DOT;

const NegativeStyle = {
BLACK_MINUS: 0, // black minus
RED_MINUS: 1, // red minus
PARENS_BLACK: 2, // black parens
PARENS_RED: 3 // red parens
}

NegativeStyle["BLACK_MINUS"] = NegativeStyle.BLACK_MINUS;
NegativeStyle["RED_MINUS"] = NegativeStyle.RED_MINUS;
NegativeStyle["PARENS_BLACK"] = NegativeStyle.PARENS_BLACK;
NegativeStyle["PARENS_RED"] = NegativeStyle.PARENS_RED;

/**
* Convert field value to specific number format.
* @param {number} nDec = number of decimals
Expand Down Expand Up @@ -1228,24 +1267,29 @@

window["AscPDF"].FormatDateValue = FormatDateValue;
window["AscPDF"].Api = {
Functions: {
AFNumber_Format: AFNumber_Format,
AFNumber_Keystroke: AFNumber_Keystroke,
AFPercent_Format: AFPercent_Format,
AFPercent_Keystroke: AFPercent_Keystroke,
AFDate_Format: AFDate_Format,
AFDate_Keystroke: AFDate_Keystroke,
AFDate_FormatEx: AFDate_FormatEx,
AFDate_KeystrokeEx: AFDate_KeystrokeEx,
AFTime_Format: AFTime_Format,
AFTime_Keystroke: AFTime_Keystroke,
AFTime_FormatEx: AFTime_FormatEx,
AFTime_KeystrokeEx: AFTime_KeystrokeEx,
AFSpecial_Format: AFSpecial_Format,
AFSpecial_Keystroke: AFSpecial_Keystroke,
AFSpecial_KeystrokeEx: AFSpecial_KeystrokeEx,
AFSimple_Calculate: AFSimple_Calculate,
AFRange_Validate: AFRange_Validate,
"Functions": {
"AFNumber_Format": AFNumber_Format,
"AFNumber_Keystroke": AFNumber_Keystroke,
"AFPercent_Format": AFPercent_Format,
"AFPercent_Keystroke": AFPercent_Keystroke,
"AFDate_Format": AFDate_Format,
"AFDate_Keystroke": AFDate_Keystroke,
"AFDate_FormatEx": AFDate_FormatEx,
"AFDate_KeystrokeEx": AFDate_KeystrokeEx,
"AFTime_Format": AFTime_Format,
"AFTime_Keystroke": AFTime_Keystroke,
"AFTime_FormatEx": AFTime_FormatEx,
"AFTime_KeystrokeEx": AFTime_KeystrokeEx,
"AFSpecial_Format": AFSpecial_Format,
"AFSpecial_Keystroke": AFSpecial_Keystroke,
"AFSpecial_KeystrokeEx": AFSpecial_KeystrokeEx,
"AFSimple_Calculate": AFSimple_Calculate,
"AFRange_Validate": AFRange_Validate,
},
"Types": {
"FormattingType": FormattingType,
"SeparatorStyle": SeparatorStyle,
"NegativeStyle": NegativeStyle
}
}
})();
Expand Down

0 comments on commit 7e393e8

Please sign in to comment.