mirror of
https://github.com/morbalint/kem2karakterlap.git
synced 2026-07-17 15:23:48 +00:00
29 lines
805 B
TypeScript
29 lines
805 B
TypeScript
import {PDFFont, PDFForm, PDFPage, PDFTextField, rgb} from "pdf-lib";
|
|
|
|
export interface TextFieldOptions {
|
|
name: string,
|
|
x: number,
|
|
y: number,
|
|
w: number,
|
|
h: number,
|
|
text?: string,
|
|
}
|
|
|
|
export type RenderTextBoxFunc = (options: TextFieldOptions) => PDFTextField;
|
|
|
|
export function addTextFieldFactory(form: PDFForm, pdfFont: PDFFont, page: PDFPage): RenderTextBoxFunc {
|
|
return (options: TextFieldOptions) => {
|
|
const field = form.createTextField(options.name)
|
|
field.setText(options.text)
|
|
field.addToPage(page, {
|
|
x: options.x,
|
|
y: options.y,
|
|
font: pdfFont,
|
|
borderColor: rgb(1, 1, 1),
|
|
borderWidth: 0,
|
|
width: options.w,
|
|
height: options.h,
|
|
})
|
|
return field
|
|
}
|
|
} |