JavaScript 필드 확장
JavaScript 필드 확장
Aspose.Pdf.Annotations.JavascriptExtensions 네임스페이스는 관리형
Acrobat JavaScript AF_ 포맷팅 함수에 대한 대응물을 포함합니다. 이러한 클래스들은
PDF 필드 표시 로직을 .NET 애플리케이션 내에서 재현하도록 해주고
JavaScript를 실행하지 않고.
FieldDateTimeFormatter은 정적 클래스입니다 — 타입에서 바로 Format을 호출하십시오.FieldNumberCurrencyFormatter 및 FieldNumberPercentFormatter은 일반
클래스 — 인스턴스를 생성한 후 Format을 호출합니다. 각 메서드는 해당 Acrobat JavaScript 함수와 동일한
매개변수를 받아들이며 포맷된 문자열을 반환합니다.
FieldDateTimeFormatter
FieldDateTimeFormatter은 Acrobat 스타일의 날짜 형식 패턴을 사용하여 원시 날짜/시간 문자열을 포맷합니다. 이는 AF_Date_Format JavaScript 함수에 해당합니다.
메서드 시그니처
public static string Format(string dateFormat, string dateValue)| 매개변수 | 유형 | 설명 |
|---|---|---|
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 은(는) 숫자 문자열을 통화 값으로 포맷합니다.
이는 AF_Number_Format JavaScript 함수에 해당합니다.
메서드 시그니처
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.50FieldNumberPercentFormatter
FieldNumberPercentFormatter은(는) 숫자 문자열을 백분율로 포맷하며, 포맷을 적용하기 전에 값을 100배합니다. 이는 AF_Percent_Format JavaScript 함수에 해당합니다.
메서드 시그니처
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}");
}
}
}