JavaScript API 레퍼런스
PDF Oxide는 JavaScript와 TypeScript를 위한 WebAssembly 바인딩을 제공합니다. npm 패키지 pdf-oxide-wasm은 Node.js, 브라우저, 번들러, Deno, Cloudflare Workers에서 동작합니다.
npm install pdf-oxide-wasm
멀티 타깃 패키징 (v0.3.38)
pdf-oxide-wasm은 이제 package.json의 조건부 exports를 통해 세 가지 빌드를 나란히 제공합니다. 런타임에 맞는 서브패스를 선택하세요 — 대부분의 환경에서는 exports 필드를 통해 자동으로 라우팅되는 최상위 import도 올바르게 해석됩니다.
| 서브패스 | 타깃 |
|---|---|
pdf-oxide-wasm/nodejs |
Node.js (CommonJS + ESM) |
pdf-oxide-wasm/bundler |
Vite, webpack, Rollup, esbuild, Bun |
pdf-oxide-wasm/web |
브라우저, Deno, Cloudflare Workers |
// Node.js
import { WasmPdfDocument } from "pdf-oxide-wasm/nodejs";
// Vite / webpack / Rollup
import init, { WasmPdfDocument } from "pdf-oxide-wasm/bundler";
await init();
// Browsers / Deno / Workers
import init, { WasmPdfDocument } from "pdf-oxide-wasm/web";
await init();
이로써 v0.3.38 이전에 브라우저 번들러에서 발생하던 ReferenceError: Can't find variable: __dirname 오류가 해결됩니다.
Rust API는 Rust API 레퍼런스를, Python API는 Python API 레퍼런스를 참고하세요. 타입 세부 정보는 타입 & Enum을 참고하세요.
일부 메서드는 Rust 빌드 기능(
rendering,signatures,barcodes,ocr-tract) 뒤에 게이팅되어 있습니다. 기본pdf-oxide-wasm패키지는 공통 기능 집합을 활성화하며, OCR은 별도의wasm-ocr빌드로 제공됩니다. 기능 지원 현황을 참고하세요.
Module Functions
패키지 최상위에서 export되는 자유 함수입니다.
import {
setLogLevel, disableLogging,
generateBarcodeSvg, generateQrSvg,
planSplitByBookmarks, splitByBookmarks,
setCryptoPolicy, cryptoPolicy, cryptoInventory, cryptoCbom,
modelManifest, prefetchAvailable,
signPdfBytes, signPdfBytesPades, hasDocumentTimestamp,
} from "pdf-oxide-wasm";
로깅
setLogLevel(level) // Set log verbosity: "off" | "error" | "warn" | "info" | "debug" | "trace"
disableLogging() // Silence all log output
바코드
generateBarcodeSvg(barcodeType, data) -> string // 1D barcode as SVG; type 0–7 (Code128, Code39, Ean13, Ean8, UpcA, Itf, Code93, Codabar)
generateQrSvg(data, errorCorrection, size) -> string // QR code as SVG; errorCorrection 0=Low 1=Medium 2=Quartile 3=High
북마크 기준 분할
planSplitByBookmarks(srcBytes, titlePrefix, ignoreCase, level, includeFrontMatter) -> Array // Plan a split without producing PDFs; returns segment descriptors
splitByBookmarks(srcBytes, titlePrefix, ignoreCase, level, includeFrontMatter) -> Array // Split at bookmark boundaries; returns [segment, bytes] pairs (level 0=all depths, 1=top-level)
암호화 거버넌스
setCryptoPolicy(spec) // Install the process-wide crypto policy ("compat" | "strict" | "fips-strict"[;…]); fail-closed
cryptoPolicy() -> string // The active crypto policy as its canonical grammar string
cryptoInventory() -> string[] // Algorithm tokens exercised so far this process
cryptoCbom() -> string // CycloneDX 1.6 Cryptographic Bill of Materials (JSON string)
OCR 모델 프로비저닝
modelManifest() -> string // JSON manifest of OCR detector/recognizer cache filenames and source URLs (host-side fetch)
prefetchAvailable() -> boolean // Whether this build can download OCR models to a local cache (always false in WASM)
서명 (자유 함수)
signPdfBytes(pdfData, cert, reason?, location?) -> Uint8Array // Sign raw PDF bytes with a WasmCertificate; returns the signed PDF
signPdfBytesPades(pdfData, cert, level, timestampToken?, revocation?, reason?, location?) -> Uint8Array // Sign at a PAdES baseline level (BB/BT/BLt); pass a pre-fetched RFC 3161 token for BT/BLt
hasDocumentTimestamp(pdfData) -> boolean // Whether the PDF carries a document-scoped /DocTimeStamp (PAdES-B-LTA)
WasmPdfDocument
PDF를 열고, 추출하고, 편집하고, 저장하기 위한 기본 클래스입니다.
import { WasmPdfDocument } from "pdf-oxide-wasm";
생성자
new WasmPdfDocument(data, password?)
원시 바이트에서 PDF 문서를 로드합니다.
| 매개변수 | 타입 | 설명 |
|---|---|---|
data |
Uint8Array |
PDF 파일 내용 |
password |
string | undefined |
암호화된 PDF용 선택적 비밀번호 |
예외: PDF가 유효하지 않거나 파싱할 수 없으면 Error를 던집니다.
const bytes = new Uint8Array(readFileSync("document.pdf"));
const doc = new WasmPdfDocument(bytes);
정적 생성자
WasmPdfDocument.openFromDocxBytes(data) -> WasmPdfDocument // Convert DOCX bytes to a PDF document
WasmPdfDocument.openFromPptxBytes(data) -> WasmPdfDocument // Convert PPTX bytes to a PDF document
WasmPdfDocument.openFromXlsxBytes(data) -> WasmPdfDocument // Convert XLSX bytes to a PDF document
핵심 읽기 전용
pageCount() -> number
문서의 페이지 수를 가져옵니다.
version() -> Uint8Array
PDF 버전을 [major, minor] 형태로 가져옵니다.
const [major, minor] = doc.version();
console.log(`PDF ${major}.${minor}`);
authenticate(password) -> boolean
암호화된 PDF를 복호화합니다. 인증에 성공하면 true를 반환합니다.
| 매개변수 | 타입 | 설명 |
|---|---|---|
password |
string |
비밀번호 문자열 |
hasStructureTree() -> boolean
문서가 구조 트리를 가진 태그 PDF인지 확인합니다.
서명 검사
signatureCount() -> number // Number of digital signatures in the document
signatures() -> WasmSignature[] // Parsed signatures (signer, reason, time, verify())
dss() -> Dss | null // Document Security Store (certs/CRLs/OCSP), or null
텍스트 추출
extractText(pageIndex, region?) -> string
단일 페이지에서 일반 텍스트를 추출합니다. 추출 범위를 제한하려면 선택적 [x, y, w, h] 영역을 전달하세요.
| 매개변수 | 타입 | 설명 |
|---|---|---|
pageIndex |
number |
0부터 시작하는 페이지 번호 |
region |
number[] | undefined |
선택적 [x, y, width, height] 클립 |
const text = doc.extractText(0);
extractAllText() -> string
모든 페이지에서 일반 텍스트를 추출하며, 폼 피드 문자로 구분합니다.
extractStructured(pageIndex) -> string
페이지의 구조화된 JSON 표현(블록, 라인, 스타일링)을 추출합니다.
extractChars(pageIndex, region?) -> Array
정확한 위치와 폰트 메타데이터를 포함한 개별 문자를 추출합니다.
| 매개변수 | 타입 | 설명 |
|---|---|---|
pageIndex |
number |
0부터 시작하는 페이지 번호 |
region |
number[] | undefined |
선택적 [x, y, width, height] 클립 |
반환값: 다음 필드를 가진 객체의 배열:
| 필드 | 타입 | 설명 |
|---|---|---|
char |
string |
문자 |
bbox |
{x, y, width, height} |
경계 상자 |
fontName |
string |
폰트 이름 |
fontSize |
number |
폰트 크기(포인트) |
fontWeight |
string |
굵기(Normal, Bold 등) |
isItalic |
boolean |
이탤릭 여부 |
color |
{r, g, b} |
RGB 색상 (0.0–1.0) |
const chars = doc.extractChars(0);
for (const c of chars) {
console.log(`'${c.char}' at (${c.bbox.x}, ${c.bbox.y})`);
}
extractPageText(pageIndex, readingOrder?) -> object
한 번의 추출 과정에서 스팬, 문자, 페이지 크기를 가져옵니다. extractSpans()와 extractChars()를 따로 호출하는 것보다 효율적입니다. 다단 PDF에는 "column_aware"를 전달하세요.
| 매개변수 | 타입 | 설명 |
|---|---|---|
pageIndex |
number |
0부터 시작하는 페이지 번호 |
readingOrder |
string | undefined |
"column_aware" 또는 "top_to_bottom" (기본값) |
반환값: 다음 필드를 가진 객체:
| 필드 | 타입 | 설명 |
|---|---|---|
spans |
Array |
스팬 객체의 배열 |
chars |
Array |
문자 객체의 배열 |
pageWidth |
number |
페이지 너비(PDF 포인트) |
pageHeight |
number |
페이지 높이(PDF 포인트) |
text |
string |
전체 텍스트 내용 |
const result = doc.extractPageText(0);
console.log(`Page: ${result.pageWidth}x${result.pageHeight} pt`);
for (const span of result.spans) {
console.log(`'${span.text}' font=${span.fontName} size=${span.fontSize}`);
}
extractSpans(pageIndex, region?, readingOrder?) -> Array
폰트 메타데이터를 포함한 스타일 텍스트 스팬을 추출합니다. 다단 PDF에는 readingOrder로 "column_aware"를 전달하세요.
| 매개변수 | 타입 | 설명 |
|---|---|---|
pageIndex |
number |
0부터 시작하는 페이지 번호 |
region |
number[] | undefined |
선택적 [x, y, width, height] 클립 |
readingOrder |
string | undefined |
"column_aware" 또는 "top_to_bottom" (기본값) |
반환값: 다음 필드를 가진 객체의 배열:
| 필드 | 타입 | 설명 |
|---|---|---|
text |
string |
텍스트 내용 |
bbox |
{x, y, width, height} |
경계 상자 |
fontName |
string |
폰트 이름 |
fontSize |
number |
폰트 크기(포인트) |
fontWeight |
string |
굵기(Normal, Bold 등) |
isItalic |
boolean |
이탤릭 여부 |
isMonospace |
boolean |
고정폭 폰트 여부 |
charWidths |
number[] |
글리프별 전진 너비 |
color |
{r, g, b} |
RGB 색상 (0.0–1.0) |
const spans = doc.extractSpans(0);
for (const span of spans) {
console.log(`"${span.text}" size=${span.fontSize}`);
}
단어, 라인, 테이블
extractWords(pageIndex, region?) -> Array // Word-level boxes with text + font metadata
extractTextLines(pageIndex, region?) -> Array // Line-level boxes, each with its words
extractTables(pageIndex, region?) -> Array // Detected tables with rows/cells (text + bboxes)
머리글 / 바닥글 아티팩트
반복되는 머리글, 바닥글, 페이지 장식 아티팩트를 감지하여 제거하거나 지웁니다.
removeHeaders(threshold) -> number // Remove detected headers across the document; returns count removed
removeFooters(threshold) -> number // Remove detected footers; returns count removed
removeArtifacts(threshold) -> number // Remove detected page artifacts; returns count removed
eraseHeader(pageIndex) // Queue an erase of the header region on a page
editHeader(pageIndex) // Mark the header region for editing on a page
eraseFooter(pageIndex) // Queue an erase of the footer region on a page
editFooter(pageIndex) // Mark the footer region for editing on a page
eraseArtifacts(pageIndex) // Queue an erase of detected artifacts on a page
영역 추출
within(pageIndex, region) -> WasmPdfPageRegion
이후의 추출을 페이지의 직사각형 영역으로 한정합니다. region은 [x, y, width, height] 형식입니다. WasmPdfPageRegion을 참고하세요.
const region = doc.within(0, [50, 600, 400, 150]);
const text = region.extractText();
형식 변환
toMarkdown(pageIndex, detectHeadings?, includeImages?, includeFormFields?) -> string
단일 페이지를 Markdown으로 변환합니다.
| 매개변수 | 타입 | 기본값 | 설명 |
|---|---|---|---|
pageIndex |
number |
– | 0부터 시작하는 페이지 번호 |
detectHeadings |
boolean |
true |
폰트 크기로 제목 감지 |
includeImages |
boolean |
true |
이미지 포함 |
includeFormFields |
boolean |
true |
폼 필드 값 포함 |
toMarkdownAll(detectHeadings?, includeImages?, includeFormFields?) -> string
모든 페이지를 Markdown으로 변환합니다.
toHtml(pageIndex, preserveLayout?, detectHeadings?, includeFormFields?) -> string
단일 페이지를 HTML로 변환합니다.
| 매개변수 | 타입 | 기본값 | 설명 |
|---|---|---|---|
pageIndex |
number |
– | 0부터 시작하는 페이지 번호 |
preserveLayout |
boolean |
false |
시각적 레이아웃 보존 |
detectHeadings |
boolean |
true |
제목 감지 |
includeFormFields |
boolean |
true |
폼 필드 값 포함 |
toHtmlAll(preserveLayout?, detectHeadings?, includeFormFields?) -> string
모든 페이지를 HTML로 변환합니다.
toPlainText(pageIndex) -> string
단일 페이지를 일반 텍스트로 변환합니다.
toPlainTextAll() -> string
모든 페이지를 일반 텍스트로 변환합니다.
Office 라운드트립
toDocxBytes() -> Uint8Array // Export the document as a DOCX file
toPptxBytes() -> Uint8Array // Export the document as a PPTX file
toXlsxBytes() -> Uint8Array // Export the document as an XLSX file
검색
search(pattern, caseInsensitive?, literal?, wholeWord?, maxResults?) -> Array
모든 페이지에서 텍스트를 검색합니다.
| 매개변수 | 타입 | 기본값 | 설명 |
|---|---|---|---|
pattern |
string |
– | 검색 패턴(문자열 또는 정규식) |
caseInsensitive |
boolean |
false |
대소문자 구분 없는 검색 |
literal |
boolean |
false |
패턴을 리터럴 문자열로 취급 |
wholeWord |
boolean |
false |
단어 단위로만 일치 |
maxResults |
number |
0 |
최대 결과 수(0 = 무제한) |
반환값: 다음 필드를 가진 객체의 배열:
| 필드 | 타입 | 설명 |
|---|---|---|
page |
number |
페이지 번호 |
text |
string |
일치한 텍스트 |
bbox |
object |
경계 상자 |
startIndex |
number |
페이지 텍스트 내 시작 인덱스 |
endIndex |
number |
페이지 텍스트 내 끝 인덱스 |
searchPage(pageIndex, pattern, caseInsensitive?, literal?, wholeWord?, maxResults?) -> Array
단일 페이지 내에서 텍스트를 검색합니다.
이미지 정보
extractImages(pageIndex) -> Array
페이지의 이미지 메타데이터를 가져옵니다.
| 필드 | 타입 | 설명 |
|---|---|---|
width |
number |
이미지 너비(픽셀) |
height |
number |
이미지 높이(픽셀) |
colorSpace |
string |
색 공간(예: DeviceRGB) |
bitsPerComponent |
number |
색 채널당 비트 수 |
bbox |
object |
페이지 내 위치 |
extractImageBytes(pageIndex) -> Array
페이지에서 원시 이미지 바이트를 추출합니다. 객체의 배열을 반환합니다:
| 필드 | 타입 | 설명 |
|---|---|---|
width |
number |
이미지 너비(픽셀) |
height |
number |
이미지 높이(픽셀) |
data |
Uint8Array |
원시 이미지 바이트 |
format |
string |
이미지 형식 |
pageImages(pageIndex) -> Array
위치 지정 작업을 위한 이미지 이름과 경계를 가져옵니다.
| 필드 | 타입 | 설명 |
|---|---|---|
name |
string |
XObject 이름 |
bounds |
number[] |
[x, y, width, height] |
matrix |
number[] |
변환 행렬 [a, b, c, d, e, f] |
벡터 콘텐츠
extractPaths(pageIndex, region?) -> Array // Vector paths (lines, curves, shapes) on a page
extractRects(pageIndex, region?) -> Array // Axis-aligned rectangles detected from path segments
extractLines(pageIndex, region?) -> Array // Straight line segments detected from path data
문서 구조
getOutline() -> Array | null
문서 북마크 / 목차를 가져옵니다. 개요가 없으면 null을 반환합니다.
getAnnotations(pageIndex) -> Array
페이지의 주석 메타데이터(타입, 사각형, 내용 등)를 가져옵니다.
pageLabels() -> Array
페이지 라벨 범위를 가져옵니다. 객체의 배열을 반환합니다:
| 필드 | 타입 | 설명 |
|---|---|---|
startPage |
number |
이 범위의 첫 페이지 |
style |
string |
번호 매기기 스타일 |
prefix |
string |
라벨 접두사 |
startValue |
number |
시작 번호 |
xmpMetadata() -> object | null
XMP 메타데이터를 가져옵니다. 존재하지 않으면 null을 반환합니다. 객체 필드는 다음과 같습니다:
| 필드 | 타입 | 설명 |
|---|---|---|
dcTitle |
string | null |
문서 제목 |
dcCreator |
string[] | null |
작성자 목록 |
dcDescription |
string | null |
설명 |
xmpCreatorTool |
string | null |
작성 도구 |
xmpCreateDate |
string | null |
생성 날짜 |
xmpModifyDate |
string | null |
수정 날짜 |
pdfProducer |
string | null |
PDF 생성기 |
폼 필드
getFormFields() -> Array
이름, 타입, 값, 플래그를 포함한 모든 폼 필드를 가져옵니다.
| 필드 | 타입 | 설명 |
|---|---|---|
name |
string |
필드 이름 |
fieldType |
string |
필드 타입(text, checkbox 등) |
value |
string |
현재 값 |
flags |
number |
필드 플래그 |
const fields = doc.getFormFields();
for (const f of fields) {
console.log(`${f.name} (${f.fieldType}) = ${f.value}`);
}
hasXfa() -> boolean
문서가 XFA 폼을 포함하는지 확인합니다.
getFormFieldValue(name) -> any
이름으로 폼 필드 값을 가져옵니다. 필드 타입에 따라 string, boolean, 또는 null을 반환합니다.
setFormFieldValue(name, value) -> void
이름으로 폼 필드 값을 설정합니다.
| 매개변수 | 타입 | 설명 |
|---|---|---|
name |
string |
필드 이름 |
value |
string | boolean |
새 필드 값 |
exportFormData(format?) -> Uint8Array
폼 데이터를 FDF(기본) 또는 XFDF로 내보냅니다.
| 매개변수 | 타입 | 기본값 | 설명 |
|---|---|---|---|
format |
string |
"fdf" |
내보내기 형식: "fdf" 또는 "xfdf" |
폼 평탄화
flattenForms() // Flatten all form fields into page content
flattenFormsOnPage(pageIndex) // Flatten forms on a specific page
flattenWarnings() -> string[] // Warnings produced by the last flatten operation
편집
메타데이터
| 메서드 | 매개변수 | 설명 |
|---|---|---|
setTitle(title) |
string |
문서 제목 설정 |
setAuthor(author) |
string |
문서 작성자 설정 |
setSubject(subject) |
string |
문서 주제 설정 |
setKeywords(keywords) |
string |
문서 키워드 설정 |
페이지 회전
| 메서드 | 매개변수 | 설명 |
|---|---|---|
pageRotation(pageIndex) |
number |
현재 회전값 가져오기(0, 90, 180, 270) |
setPageRotation(pageIndex, degrees) |
number, number |
절대 회전값 설정 |
rotatePage(pageIndex, degrees) |
number, number |
현재 회전값에 더하기 |
rotateAllPages(degrees) |
number |
모든 페이지 회전 |
페이지 크기
| 메서드 | 매개변수 | 설명 |
|---|---|---|
pageMediaBox(pageIndex) |
number |
MediaBox 가져오기 [llx, lly, urx, ury] |
setPageMediaBox(pageIndex, llx, lly, urx, ury) |
number, ... |
MediaBox 설정 |
pageCropBox(pageIndex) |
number |
CropBox 가져오기(null일 수 있음) |
setPageCropBox(pageIndex, llx, lly, urx, ury) |
number, ... |
CropBox 설정 |
cropMargins(left, right, top, bottom) |
number, ... |
모든 페이지 여백 자르기 |
페이지 작업
deletePage(index) // Delete a page by index
movePage(fromIndex, toIndex) // Move a page to a new position
extractPages(pages) -> Uint8Array // Build a new PDF from the given page indices
지우기 / 화이트아웃
| 메서드 | 매개변수 | 설명 |
|---|---|---|
eraseRegion(pageIndex, llx, lly, urx, ury) |
number, ... |
영역 지우기 |
eraseRegions(pageIndex, rects) |
number, Float32Array |
여러 영역 지우기 |
clearEraseRegions(pageIndex) |
number |
대기 중인 지우기 작업 취소 |
주석 & 마스킹
| 메서드 | 매개변수 | 설명 |
|---|---|---|
flattenPageAnnotations(pageIndex) |
number |
페이지의 주석 평탄화 |
flattenAllAnnotations() |
– | 모든 주석 평탄화 |
applyPageRedactions(pageIndex) |
number |
페이지의 마스킹 적용 |
applyAllRedactions() |
– | 모든 마스킹 적용 |
addRedaction(page, x0, y0, x1, y1, fill?) |
number, ... |
마스킹 상자 대기열에 추가(선택적 [r,g,b] 채우기) |
redactionCount(page) |
number |
페이지에 대기 중인 마스킹 개수 |
applyRedactionsDestructive(scrubMetadata?) |
boolean |
콘텐츠를 파괴적으로 제거; 마스킹 보고서 반환 |
sanitizeDocument(scrubMetadata?, removeJavascript?, removeEmbeddedFiles?) |
boolean, ... |
메타데이터, 스크립트, 임베디드 파일 제거; 보고서 반환 |
병합 & 임베드
mergeFrom(data) -> number
다른 PDF의 페이지를 병합합니다. 병합된 페이지 수를 반환합니다.
| 매개변수 | 타입 | 설명 |
|---|---|---|
data |
Uint8Array |
소스 PDF 파일 바이트 |
embedFile(name, data) -> void
PDF에 파일을 첨부합니다.
| 매개변수 | 타입 | 설명 |
|---|---|---|
name |
string |
첨부 파일의 파일명 |
data |
Uint8Array |
파일 내용 |
이미지 조작
| 메서드 | 매개변수 | 설명 |
|---|---|---|
repositionImage(pageIndex, name, x, y) |
number, string, number, number |
이미지 이동 |
resizeImage(pageIndex, name, w, h) |
number, string, number, number |
이미지 크기 조정 |
setImageBounds(pageIndex, name, x, y, w, h) |
number, string, ... |
이미지 경계 설정 |
분류 & 자동 추출
classifyDocument() -> string // Classify the whole document (e.g. born-digital vs scanned)
classifyPage(pageIndex) -> string // Classify a single page
extractTextAuto(pageIndex) -> string // Auto-pick native vs OCR extraction for a page
extractPageAuto(pageIndex, optionsJson?) -> string // Auto-extraction returning a structured JSON page
검증
validatePdfA(level) -> object // Validate against a PDF/A conformance level (e.g. "2b")
convertToPdfA(level) -> object // Convert toward a PDF/A level; returns a report
validatePdfUa(level?) -> object // Validate against PDF/UA accessibility
validatePdfX(level?) -> object // Validate against a PDF/X print level
렌더링
rendering 기능이 필요합니다.
| 메서드 | 매개변수 | 반환값 | 설명 |
|---|---|---|---|
renderPage(pageIndex, dpi?) |
number, number |
Uint8Array |
페이지를 PNG 바이트로 렌더링(기본 150 dpi) |
flattenToImages(dpi?) |
number |
Uint8Array |
모든 페이지를 이미지 기반 PDF로 평탄화 |
OCR
wasm-ocr 빌드가 필요합니다. WasmOcrEngine을 참고하세요.
extractTextOcr(pageIndex, engine) -> string
호스트에서 빌드한 WasmOcrEngine을 사용해 페이지에 대해 WASM 내장 OCR 파이프라인을 실행합니다. 읽기 순서대로 인식된 텍스트를 반환합니다.
const text = doc.extractTextOcr(0, engine);
저장
save() -> Uint8Array
편집된 PDF를 바이트로 저장합니다. saveToBytes()도 별칭으로 사용할 수 있습니다.
saveWithOptions(compress?, garbageCollect?, linearize?) -> Uint8Array
명시적인 직렬화 옵션으로 저장합니다.
| 매개변수 | 타입 | 기본값 | 설명 |
|---|---|---|---|
compress |
boolean |
true |
객체 스트림 압축 |
garbageCollect |
boolean |
true |
참조되지 않는 객체 제거 |
linearize |
boolean |
false |
선형화된(“빠른 웹 보기”) PDF 생성 |
saveEncryptedToBytes(password, ownerPassword?, allowPrint?, allowCopy?, allowModify?, allowAnnotate?) -> Uint8Array
AES-256 암호화로 저장합니다.
| 매개변수 | 타입 | 기본값 | 설명 |
|---|---|---|---|
password |
string |
– | 사용자 비밀번호 |
ownerPassword |
string |
사용자 비밀번호 | 소유자 비밀번호 |
allowPrint |
boolean |
true |
인쇄 허용 |
allowCopy |
boolean |
true |
복사 허용 |
allowModify |
boolean |
true |
수정 허용 |
allowAnnotate |
boolean |
true |
주석 허용 |
free()
WASM 메모리를 해제합니다. 문서 사용이 끝나면 항상 호출하세요.
WasmPdfPageRegion
WasmPdfDocument.within(pageIndex, region)이 반환하는 영역 핸들입니다. 추출 메서드가 해당 직사각형으로 한정됩니다.
extractText() -> string // Plain text within the region
extractChars() -> Array // Characters within the region
extractWords() -> Array // Words within the region
extractTextLines() -> Array // Text lines within the region
extractTables() -> Array // Tables within the region
extractImages() -> Array // Images within the region
extractPaths() -> Array // Vector paths within the region
extractRects() -> Array // Rectangles within the region
extractLines() -> Array // Line segments within the region
extractTextOcr(engine?) -> string // OCR text within the region (wasm-ocr build)
WasmPdf
새 PDF를 생성하기 위한 팩토리 클래스입니다.
import { WasmPdf } from "pdf-oxide-wasm";
정적 메서드
WasmPdf.fromMarkdown(content, title?, author?) -> WasmPdf // Create a PDF from Markdown text
WasmPdf.fromHtml(content, title?, author?) -> WasmPdf // Create a PDF from HTML
WasmPdf.fromText(content, title?, author?) -> WasmPdf // Create a PDF from plain text
WasmPdf.fromBytes(data) -> WasmPdf // Open an existing PDF from bytes for modification
WasmPdf.fromImageBytes(data) -> WasmPdf // Single-page PDF from one image (JPEG/PNG)
WasmPdf.fromMultipleImageBytes(imagesArray) -> WasmPdf // Multi-page PDF, one page per image
WasmPdf.merge(pdfs) -> WasmPdf // Merge an array of PDF byte buffers into one
WasmPdf.fromHtmlCss(html, css, fontBytes) -> WasmPdf // HTML + CSS with a single embedded font
WasmPdf.fromHtmlCssWithFonts(html, css, fonts) -> WasmPdf // HTML + CSS with multiple [name, bytes] fonts
| 매개변수 | 타입 | 설명 |
|---|---|---|
content |
string |
소스 콘텐츠(Markdown / HTML / 텍스트) |
title |
string | undefined |
문서 제목 |
author |
string | undefined |
문서 작성자 |
data |
Uint8Array |
PDF 또는 이미지 파일 바이트 |
imagesArray |
Uint8Array[] |
이미지 파일 바이트의 배열 |
pdfs |
Uint8Array[] |
병합할 PDF 파일 바이트의 배열 |
인스턴스 메서드
toBytes() -> Uint8Array
PDF를 바이트로 가져옵니다.
size -> number
PDF 크기(바이트, 읽기 전용 게터).
const pdf = WasmPdf.fromMarkdown("# Hello World\n\nThis is a PDF.");
console.log(`PDF size: ${pdf.size} bytes`);
writeFileSync("output.pdf", pdf.toBytes());
WasmDocumentBuilder
PDF를 페이지 단위로 구성하기 위한 유연한 저수준 페이지 레이아웃 빌더입니다. WasmFluentPageBuilder와 함께 사용하세요.
import { WasmDocumentBuilder } from "pdf-oxide-wasm";
const builder = new WasmDocumentBuilder();
문서 설정
new WasmDocumentBuilder() // Create an empty builder
title(title) // Set document title
author(author) // Set document author
subject(subject) // Set document subject
keywords(keywords) // Set document keywords
creator(creator) // Set the creator tool name
onOpen(script) // Set a document-level open JavaScript action
taggedPdfUa1() // Enable Tagged PDF / PDF/UA-1 output
language(lang) // Set the document language (e.g. "en-US")
roleMap(custom, standard) // Map a custom structure tag to a standard role
registerEmbeddedFont(name, font) // Register a WasmEmbeddedFont under a name
페이지 생성 & 출력
a4Page() -> WasmFluentPageBuilder // Start a new A4 page
letterPage() -> WasmFluentPageBuilder // Start a new US Letter page
page(width, height) -> WasmFluentPageBuilder // Start a custom-size page (points)
commitPage(page) // Commit a completed page builder
build() -> Uint8Array // Finish and return the PDF bytes
toBytesEncrypted(userPassword, ownerPassword?) -> Uint8Array // Finish with AES-256 encryption
WasmFluentPageBuilder
a4Page() / letterPage() / page()가 반환하는 페이지별 빌더입니다. 작업을 큐에 쌓은 다음 done(builder)(또는 builder.commitPage(page))로 커밋하세요.
텍스트 & 흐름
font(name, size) // Set the current font and size
at(x, y) // Move the cursor to an absolute position
text(text) // Draw text at the cursor
heading(level, text) // Draw a heading (level 1–6)
paragraph(text) // Draw a wrapped paragraph
space(points) // Advance the cursor vertically
horizontalRule() // Draw a horizontal rule
newline() // Advance to the next line
columns(columnCount, gapPt, text) // Lay text out in N balanced columns
footnote(refMark, noteText) // Add a footnote marker + bottom-of-page note
인라인 런
inline(text) // Append an inline text run
inlineBold(text) // Append a bold inline run
inlineItalic(text) // Append an italic inline run
inlineColor(r, g, b, text) // Append a colored inline run (RGB 0.0–1.0)
링크 & 폼 액션
linkUrl(url) // Wrap the last element in a URL link
linkPage(page) // Link to another page index
linkNamed(destination) // Link to a named destination
linkJavascript(script) // Attach a JavaScript link action
onOpen(script) // Page open action
onClose(script) // Page close action
fieldKeystroke(script) // Keystroke JavaScript for the last field
fieldFormat(script) // Format JavaScript for the last field
fieldValidate(script) // Validate JavaScript for the last field
fieldCalculate(script) // Calculate JavaScript for the last field
마크업 주석
highlight(r, g, b) // Highlight the last text run (RGB 0.0–1.0)
underline(r, g, b) // Underline the last text run
strikeout(r, g, b) // Strike out the last text run
squiggly(r, g, b) // Squiggly-underline the last text run
stickyNote(text) // Add a sticky note at the cursor
stickyNoteAt(x, y, text) // Add a sticky note at an absolute position
stamp(name) // Add a rubber-stamp annotation (e.g. "Approved")
freeText(x, y, w, h, text) // Add a free-text annotation box
watermark(text) // Add a text watermark
watermarkConfidential() // Add a "CONFIDENTIAL" watermark
watermarkDraft() // Add a "DRAFT" watermark
AcroForm 위젯
textField(name, x, y, w, h, defaultValue?) // Add a text field
checkbox(name, x, y, w, h, checked) // Add a checkbox
comboBox(name, x, y, w, h, options, selected?) // Add a dropdown combo box
radioGroup(name, values, xs, ys, ws, hs, selected?) // Add a radio-button group (parallel arrays)
pushButton(name, x, y, w, h, caption) // Add a clickable push button
signatureField(name, x, y, w, h) // Add an unsigned signature placeholder
바코드 & 이미지
barcode1d(barcodeType, data, x, y, w, h) // Draw a 1D barcode (type 0–7)
barcodeQr(data, x, y, size) // Draw a QR code
imageWithAlt(bytes, x, y, w, h, altText) // Embed an image with accessibility alt text
imageArtifact(bytes, x, y, w, h) // Embed a decorative image as an /Artifact
그래픽 프리미티브
rect(x, y, w, h) // Stroked 1pt rectangle outline
filledRect(x, y, w, h, r, g, b) // Filled rectangle (RGB 0.0–1.0)
line(x1, y1, x2, y2) // 1pt black line
strokeRect(x, y, w, h, width, r, g, b) // Stroked rectangle, explicit width + color
strokeRectDashed(x, y, w, h, width, r, g, b, dash, phase) // Dashed rectangle border
strokeLine(x1, y1, x2, y2, width, r, g, b) // Line with explicit width + color
strokeLineDashed(x1, y1, x2, y2, width, r, g, b, dash, phase) // Dashed line
textInRect(x, y, w, h, text, align) // Lay text inside a rectangle (align 0/1/2)
레이아웃 헬퍼 & 종료
measure(text) -> number // Rendered width of text in the current font (points)
remainingSpace() -> number // Vertical space left on the page (points)
newPageSameSize() // Start a new page with the same dimensions
table(spec) // Draw a buffered table from a spec object
streamingTable(spec) -> WasmStreamingTable // Open a streaming table for large datasets
done(builder) // Commit this page's queued ops to the document builder
table(spec)의 spec 객체는 { columns: [{ header, width, align }], rows: [[...]], hasHeader }를 사용합니다. streamingTable(spec)의 spec은 { repeatHeader, mode, sampleRows, minColWidthPt, maxColWidthPt, maxRowspan, batchSize }를 추가합니다.
WasmStreamingTable
WasmFluentPageBuilder.streamingTable(spec)이 반환하는 행 스트리밍 테이블 핸들입니다. 행을 점진적으로 추가한 다음 finish()를 호출하세요.
columnCount() -> number // Number of columns
pendingRowCount() -> number // Rows in the current un-flushed batch
batchCount() -> number // Number of completed batches
pushRow(cells) // Push one row (array of cell strings)
pushRowSpan(cells) // Push a row whose cells may carry rowspans
flush() // Flush the current batch
finish() // Finalize the table and replay it into the page
WasmEmbeddedFont
WasmDocumentBuilder.registerEmbeddedFont를 통해 임베딩하기 위해 등록된 폰트입니다.
WasmEmbeddedFont.fromBytes(data, name?) -> WasmEmbeddedFont // Load a TTF/OTF font from bytes
font.name -> string // The font's resolved name (getter)
페이지 템플릿
여러 페이지에 걸쳐 적용되는 재사용 가능한 머리글/바닥글 장식입니다.
WasmArtifactStyle
new WasmArtifactStyle() // Default style
font(name, size) -> this // Set font family and size
bold() -> this // Make the text bold
color(r, g, b) -> this // Set the text color (RGB 0.0–1.0)
WasmArtifact
new WasmArtifact() // Empty artifact
WasmArtifact.left(text) -> WasmArtifact // Left-aligned artifact text
WasmArtifact.center(text) -> WasmArtifact // Center-aligned artifact text
WasmArtifact.right(text) -> WasmArtifact // Right-aligned artifact text
withStyle(style) -> this // Apply a WasmArtifactStyle
withOffset(offset) -> this // Set the vertical offset from the edge
WasmHeader / WasmFooter
new WasmHeader() // Empty header (WasmFooter is identical)
WasmHeader.left(text) -> WasmHeader // Left-aligned header text
WasmHeader.center(text) -> WasmHeader // Center-aligned header text
WasmHeader.right(text) -> WasmHeader // Right-aligned header text
WasmPageTemplate
new WasmPageTemplate() // Empty template
header(header) -> this // Set the page header artifact
footer(footer) -> this // Set the page footer artifact
skipFirstPage() -> this // Omit header/footer on the first page
디지털 서명
signatures 기능이 필요합니다.
WasmCertificate
WasmCertificate.load(data) -> WasmCertificate // Load a DER certificate + key bundle
WasmCertificate.loadPem(certPem, keyPem) -> WasmCertificate // Load from PEM cert + key strings
WasmCertificate.loadPkcs12(data, password) -> WasmCertificate // Load from a PKCS#12 (.p12/.pfx) blob
cert.subject -> string // Subject distinguished name (getter)
cert.issuer -> string // Issuer distinguished name (getter)
cert.serial -> string // Serial number (getter)
cert.validity -> bigint[] // [notBefore, notAfter] as unix seconds (getter)
cert.isValid -> boolean // Whether the certificate is currently valid (getter)
WasmSignature
WasmPdfDocument.signatures()가 반환합니다.
sig.signerName -> string | null // Signer common name (getter)
sig.reason -> string | null // Signing reason (getter)
sig.location -> string | null // Signing location (getter)
sig.contactInfo -> string | null // Signer contact info (getter)
sig.signingTime -> bigint | null // Signing time as unix seconds (getter)
sig.coversWholeDocument -> boolean // Whether the signature covers the entire file (getter)
sig.padesLevel -> PadesLevel // PAdES baseline level of the signature (getter)
sig.verify() -> boolean // Verify the signature cryptographically
sig.verifyDetached(pdfData) -> boolean // Verify including a messageDigest check against the bytes
WasmTimestamp
WasmTimestamp.parse(data) -> WasmTimestamp // Parse a DER TimeStampToken / TSTInfo
ts.time -> bigint // Timestamp time as unix seconds (getter)
ts.serial -> string // Serial number (getter)
ts.policyOid -> string // TSA policy OID (getter)
ts.tsaName -> string // TSA name (getter)
ts.hashAlgorithm -> number // Imprint hash algorithm id (getter)
ts.messageImprint -> Uint8Array // The message imprint digest (getter)
ts.verify() -> boolean // Verify the timestamp token
WasmRevocationMaterial
signPdfBytesPades를 위한 오프라인 PAdES-B-LT 검증 자료입니다.
new WasmRevocationMaterial() // Empty material set
addCert(der) // Add a DER X.509 certificate
addCrl(der) // Add a DER CRL
addOcsp(der) // Add a DER OCSP response
Dss
WasmPdfDocument.dss()가 반환하는 파싱된 Document Security Store입니다.
dss.certCount -> number // Number of DER certificates (getter)
getCert(i) -> Uint8Array | undefined // i-th DER certificate
dss.crlCount -> number // Number of DER CRLs (getter)
getCrl(i) -> Uint8Array | undefined // i-th DER CRL
dss.ocspCount -> number // Number of DER OCSP responses (getter)
getOcsp(i) -> Uint8Array | undefined // i-th DER OCSP response
dss.vri -> string[] // Per-signature VRI keys (uppercase-hex SHA-1 of /Contents) (getter)
OCR
OCR은 별도의 wasm-ocr 빌드에서 순수 Rust tract 백엔드를 통해 완전히 WASM 내부에서 실행됩니다. 모델은 호스트 측에서 전달됩니다 — 디텍터/리코그나이저 ONNX 파일과 사전(modelManifest() 참고)을 가져온 다음 바이트를 생성자에 넘기세요.
WasmOcrEngine
new WasmOcrEngine(detModel, recModel, dict, config?) // Build from host-supplied model bytes
engine.ocrImage(imageBytes) -> string // OCR a raw image (PNG/JPEG/TIFF); returns JSON {text, confidence, spans}
| 매개변수 | 타입 | 설명 |
|---|---|---|
detModel |
Uint8Array |
DBNet 디텍터 ONNX 바이트 |
recModel |
Uint8Array |
SVTR 리코그나이저 ONNX 바이트 |
dict |
string |
리코그나이저 문자 사전, 한 줄에 한 문자 |
config |
WasmOcrConfig | undefined |
예약됨(튜닝된 기본값 사용) |
WasmOcrConfig
new WasmOcrConfig() // OCR configuration object (reserved for future tuning)
Enum
Align
textInRect와 테이블 열 spec에서 사용하는 텍스트/셀 정렬 판별자입니다.
Align.Left // 0
Align.Center // 1
Align.Right // 2
PadesLevel
signPdfBytesPades와 WasmSignature.padesLevel에서 사용하는 PAdES 베이스라인 레벨입니다.
PadesLevel.BB // 0 — signed attrs incl. ESS signing-certificate-v2
PadesLevel.BT // 1 — B-B + RFC 3161 signature-time-stamp
PadesLevel.BLt // 2 — B-T + Document Security Store (DSS/VRI)
PadesLevel.BLta // 3 — B-LT + document-scoped /DocTimeStamp
기능 지원 현황
일부 기능은 Rust 빌드 기능 뒤에 게이팅되어 있습니다. 기본 pdf-oxide-wasm 패키지는 공통 기능 집합을 활성화하며, OCR은 별도의 wasm-ocr 빌드로 제공됩니다.
| 기능 | WASM | 비고 |
|---|---|---|
| 텍스트 추출 | 지원 | 완전 지원 |
| 구조화 추출 | 지원 | 문자, 스팬, 단어, 라인, 테이블 |
| PDF 생성 | 지원 | Markdown, HTML, 텍스트, 이미지, DocumentBuilder |
| PDF 편집 | 지원 | 메타데이터, 회전, 크기, 지우기, 페이지 |
| 폼 필드 | 지원 | 읽기, 쓰기, 내보내기, 평탄화, 빌드 |
| 검색 | 지원 | 완전한 정규식 지원 |
| 암호화 | 지원 | AES-256 읽기 및 쓰기 |
| 주석 | 지원 | 읽기, 평탄화, 마스킹, 정화 |
| PDF 병합 / 분할 | 지원 | 페이지 병합 및 북마크 기준 분할 |
| 임베디드 파일 | 지원 | PDF에 파일 첨부 |
| 페이지 라벨 / XMP | 지원 | 페이지 라벨 및 XMP 메타데이터 읽기 |
| Office 라운드트립 | 지원 | DOCX/PPTX/XLSX 가져오기 및 내보내기 |
| 검증 | 지원 | PDF/A, PDF/UA, PDF/X |
| 바코드 | 지원 (barcodes) |
1D + QR을 SVG 또는 페이지 이미지로 |
| 렌더링 | 지원 (rendering) |
페이지 → PNG, 이미지로 평탄화 |
| 디지털 서명 | 지원 (signatures) |
서명, PAdES B-LT, 검증, 타임스탬프 |
| OCR | wasm-ocr 빌드 |
WASM 내장 tract OCR; 모델은 호스트 측에서 가져옴 |
오류 처리
실패할 수 있는 모든 메서드는 JavaScript Error 객체를 던집니다:
try {
const doc = new WasmPdfDocument(new Uint8Array([0, 1, 2]));
} catch (e) {
console.error(`Failed to open: ${e.message}`);
}
TypeScript
전체 타입 정의가 패키지에 포함되어 있습니다:
import { WasmPdfDocument, WasmPdf } from "pdf-oxide-wasm";
const doc: WasmPdfDocument = new WasmPdfDocument(bytes);
const text: string = doc.extractText(0);
const pdf: WasmPdf = WasmPdf.fromMarkdown("# Hello");
Other Language Bindings
PDF Oxide는 모든 주요 생태계를 위한 네이티브 바인딩을 제공합니다: Rust, Python, Node.js, C#, Golang, Java, PHP, Ruby, C++, Swift, Kotlin, Dart, R, Julia, Zig, Scala, Clojure, Objective-C, Elixir
다음 단계
- 타입 & 열거형 — 모든 공유 타입과 열거형
- Page API 레퍼런스 — 바인딩 간 일관된 페이지 단위 순회
- WASM 시작하기 — 튜토리얼