הרחבות שדה JavaScript

הרחבות שדה JavaScript

הרחבות שדה JavaScript

המרחב השמות Aspose.Pdf.Annotations.JavascriptExtensions מכיל מקבילים מנוהלים לפונקציות העיצוב AF_ של Acrobat JavaScript. מחלקות אלו מאפשרות לך לשחזר את לוגיקת הצגת השדות של PDF בתוך היישום .NET שלך ללא הרצת JavaScript.

FieldDateTimeFormatter היא מחלקה סטטית — קראו לFormat ישירות על הסוג.
FieldNumberCurrencyFormatter וFieldNumberPercentFormatter הן מחלקות רגילות — צרו מופע, ואז קראו לFormat. כל שיטה מקבלת את אותם הפרמטרים כמו הפונקציה המתאימה ב‑Acrobat JavaScript ומחזירה
מחרוזת מעוצבת.


FieldDateTimeFormatter

FieldDateTimeFormatter מעצב מחרוזת תאריך/זמן גולמית באמצעות תבנית תאריך בסגנון Acrobat. הוא תואם לפונקציית JavaScript AF_Date_Format.

חתימת שיטה

public static string Format(string dateFormat, string dateValue)
ParameterTypeDescription
dateFormatstringתבנית תאריך בסגנון Acrobat (למשל "mm/dd/yyyy")
dateValuestringמחרוזת תאריך גולמית לעיצוב

דוגמה

using Aspose.Pdf.Annotations.JavascriptExtensions;
string result = FieldDateTimeFormatter.Format("mm/dd/yyyy", "2026-06-11");
Console.WriteLine(result); // 06/11/2026

אם לא ניתן לנתח את ערך הקלט, הפורמטור מחזיר את הערך המקורי ללא שינוי.


FieldNumberCurrencyFormatter

FieldNumberCurrencyFormatter מעצב מחרוזת מספרית כערך מטבע.
זה תואם לפונקציית JavaScript AF_Number_Format.

חתימת שיטה

public string Format(
    int precision,
    int sepStyle,
    int negStyle,
    string currencySymbol,
    bool isPrependCurrency,
    string fieldValue)
פרמטרסוגתיאור
precisionintמספר המקומות העשרוניים
sepStyleintסגנון מפריד אלפים (0 = פסיק, 1 = ללא, 2 = נקודה)
negStyleintסגנון מספר שלילי (0 = מינוס, 1 = סוגריים, 2 = אדום)
currencySymbolstringסמל שמצורף לפני או אחרי (למשל "$")
isPrependCurrencyboolכאשר true הסמל מצורף לפני; אחרת מצורף אחרי
fieldValuestringמחרוזת מספרית לעיצוב

דוגמה

using Aspose.Pdf.Annotations.JavascriptExtensions;
var formatter = new FieldNumberCurrencyFormatter();
string result = formatter.Format(
    precision: 2,
    sepStyle: 0,
    negStyle: 0,
    currencySymbol: "$",
    isPrependCurrency: true,
    fieldValue: "1234.5");
Console.WriteLine(result); // $1,234.50

מתאם אחוז מספר שדה

FieldNumberPercentFormatter מעצב מחרוזת מספרית כאחוז, מכפיל את הערך ב‑100 לפני יישום העיצוב. זה תואם לפונקציית JavaScript AF_Percent_Format.

חתימת שיטה

public string Format(
    int precision,
    int sepStyle,
    bool isPrependPercent,
    string fieldValue)
ParameterTypeDescription
precisionintמספר מקומות עשרוניים
sepStyleintסגנון מפריד אלפים
isPrependPercentboolכאשר true הסימן % מצורף בתחילת המחרוזת; אחרת מצורף בסופה
fieldValuestringמחרוזת מספרית לעיצוב (מוכפלת ב‑100)

דוגמה

using Aspose.Pdf.Annotations.JavascriptExtensions;
var formatter = new FieldNumberPercentFormatter();
string result = formatter.Format(
    precision: 1,
    sepStyle: 0,
    isPrependPercent: false,
    fieldValue: "0.1234");
Console.WriteLine(result); // 12.3%

שימוש במעבדים בלולאת עיבוד טפסים

התבנית הבאה מיישמת עיצוב מטבע לכל ערכי שדות הטקסט בטופס PDF:

using Aspose.Pdf;
using Aspose.Pdf.Annotations.JavascriptExtensions;
byte[] data = File.ReadAllBytes("form.pdf");
using var doc = Document.Open(data);
if (doc.Form is not null)
{
    var currencyFormatter = new FieldNumberCurrencyFormatter();
    foreach (var field in doc.Form.Fields)
    {
        if (field.Value is not null)
        {
            string formatted = currencyFormatter.Format(
                precision: 2,
                sepStyle: 0,
                negStyle: 0,
                currencySymbol: "$",
                isPrependCurrency: true,
                fieldValue: field.Value);
            Console.WriteLine($"{field.Name}: {formatted}");
        }
    }
}

ראה גם

 עברית