JavaScript Alan Uzantıları
JavaScript Alan Uzantıları
Aspose.Pdf.Annotations.JavascriptExtensions ad alanı, Acrobat JavaScript AF_ biçimlendirme işlevlerine yönetilen karşılıkları içerir. Bu sınıflar, JavaScript çalıştırmadan .NET uygulamanız içinde PDF alan görüntüleme mantığını yeniden oluşturmanıza olanak tanır.
FieldDateTimeFormatter bir statik sınıftır — Format‘yi doğrudan tip üzerinde çağırın.FieldNumberCurrencyFormatter ve FieldNumberPercentFormatter normal
sınıflardır — bir örnek oluşturun, ardından Format‘yi çağırın. Her yöntem, ilgili Acrobat JavaScript işleviyle aynı parametreleri kabul eder ve
biçimlendirilmiş bir dize döndürür.
FieldDateTimeFormatter
FieldDateTimeFormatter, ham bir tarih/saat dizesini Acrobat tarzı tarih biçimlendirme deseni kullanarak biçimlendirir. Bu, AF_Date_Format JavaScript işlevine karşılık gelir.
Yöntem imzası
public static string Format(string dateFormat, string dateValue)| Parametre | Tür | Açıklama |
|---|---|---|
dateFormat | string | Acrobat tarzı tarih formatı deseni (ör. "mm/dd/yyyy") |
dateValue | string | Biçimlendirilecek ham tarih dizesi |
Örnek
using Aspose.Pdf.Annotations.JavascriptExtensions;
string result = FieldDateTimeFormatter.Format("mm/dd/yyyy", "2026-06-11");
Console.WriteLine(result); // 06/11/2026Girdi değeri ayrıştırılamazsa, biçimlendirici orijinal değeri değişmeden döndürür.
FieldNumberCurrencyFormatter
FieldNumberCurrencyFormatter sayısal bir dizeyi para birimi değeri olarak biçimlendirir. AF_Number_Format JavaScript işlevine karşılık gelir.
Yöntem imzası
public string Format(
int precision,
int sepStyle,
int negStyle,
string currencySymbol,
bool isPrependCurrency,
string fieldValue)| Parametre | Tür | Açıklama |
|---|---|---|
precision | int | Ondalık basamak sayısı |
sepStyle | int | Binlik ayırıcı stili (0 = virgül, 1 = yok, 2 = nokta) |
negStyle | int | Negatif sayı stili (0 = eksi, 1 = parantez, 2 = kırmızı) |
currencySymbol | string | Sembol önüne eklenen ya da sonuna eklenen (ör. "$") |
isPrependCurrency | bool | true olduğunda sembol önüne eklenir; aksi takdirde sonuna eklenir |
fieldValue | string | Biçimlendirilecek sayısal dize |
Örnek
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.50FieldNumberPercentFormatter
FieldNumberPercentFormatter sayısal bir dizeyi yüzde olarak biçimlendirir, biçimi uygulamadan önce değeri 100 ile çarpar. Bu, AF_Percent_Format JavaScript işlevine karşılık gelir.
Yöntem imzası
public string Format(
int precision,
int sepStyle,
bool isPrependPercent,
string fieldValue)| Parameter | Type | Description |
|---|---|---|
precision | int | Ondalık basamak sayısı |
sepStyle | int | Binlik ayırıcı stili |
isPrependPercent | bool | true olduğunda % sembolü başa eklenir; aksi takdirde sona eklenir |
fieldValue | string | Biçimlendirilecek sayısal dize (100 ile çarpılır) |
Örnek
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%Form işleme döngüsünde biçimlendiricileri kullanma
Aşağıdaki desen, bir PDF formundaki tüm metin alanı değerlerine para birimi biçimlendirmesi uygular:
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}");
}
}
}