הרחבות שדה 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)| Parameter | Type | Description |
|---|---|---|
dateFormat | string | תבנית תאריך בסגנון Acrobat (למשל "mm/dd/yyyy") |
dateValue | string | מחרוזת תאריך גולמית לעיצוב |
דוגמה
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)| פרמטר | סוג | תיאור |
|---|---|---|
precision | int | מספר המקומות העשרוניים |
sepStyle | int | סגנון מפריד אלפים (0 = פסיק, 1 = ללא, 2 = נקודה) |
negStyle | int | סגנון מספר שלילי (0 = מינוס, 1 = סוגריים, 2 = אדום) |
currencySymbol | string | סמל שמצורף לפני או אחרי (למשל "$") |
isPrependCurrency | bool | כאשר true הסמל מצורף לפני; אחרת מצורף אחרי |
fieldValue | string | מחרוזת מספרית לעיצוב |
דוגמה
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)| Parameter | Type | Description |
|---|---|---|
precision | int | מספר מקומות עשרוניים |
sepStyle | int | סגנון מפריד אלפים |
isPrependPercent | bool | כאשר true הסימן % מצורף בתחילת המחרוזת; אחרת מצורף בסופה |
fieldValue | string | מחרוזת מספרית לעיצוב (מוכפלת ב‑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}");
}
}
}