mirror of
https://github.com/morbalint/kem2karakterlap.git
synced 2026-07-17 23:33:48 +00:00
add README.md and form field font workaround
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
## KéM 2e karakterlap
|
||||||
|
|
||||||
|
A projekt célja, a Kard és Mágia második kiadásához kitölthető PDF karakterlap előállítása.
|
||||||
|
|
||||||
|
## Hogy használd?
|
||||||
|
|
||||||
|
1. `yarn install`
|
||||||
|
2. `tsc -w`
|
||||||
|
3. `node dist/index.js`
|
||||||
BIN
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
import {PageSizes, PDFDocument, PDFFont, PDFPage, rgb} from "pdf-lib";
|
import {PDFDocument, PDFPage, rgb} from "pdf-lib";
|
||||||
import fs from "fs/promises";
|
import fs from "fs/promises";
|
||||||
import fontKit from "@pdf-lib/fontkit"
|
import fontKit from "@pdf-lib/fontkit"
|
||||||
|
|
||||||
@@ -12,17 +12,21 @@ export async function Karlap() {
|
|||||||
const form = doc.getForm()
|
const form = doc.getForm()
|
||||||
|
|
||||||
const page0 = doc.getPage(0)
|
const page0 = doc.getPage(0)
|
||||||
|
page0.setFont(pdfFont)
|
||||||
|
|
||||||
const addTextFieldToPage = (page: PDFPage) => (options: {name: string, x: number, y: number, w: number, h: number}) => {
|
const addTextFieldToPage = (page: PDFPage) => (options: {name: string, x: number, y: number, w: number, h: number, text?: string}) => {
|
||||||
const field = form.createTextField(options.name)
|
const field = form.createTextField(options.name)
|
||||||
field.addToPage(page0, {
|
field.setText(options.text)
|
||||||
|
field.addToPage(page, {
|
||||||
x: options.x,
|
x: options.x,
|
||||||
y: options.y,
|
y: options.y,
|
||||||
font: pdfFont,
|
font: pdfFont,
|
||||||
borderColor: rgb(1,1,1),
|
borderColor: rgb(1,1,1),
|
||||||
|
borderWidth: 0,
|
||||||
width: options.w,
|
width: options.w,
|
||||||
height: options.h,
|
height: options.h,
|
||||||
})
|
})
|
||||||
|
return field
|
||||||
}
|
}
|
||||||
|
|
||||||
const addTextField0 = addTextFieldToPage(page0)
|
const addTextField0 = addTextFieldToPage(page0)
|
||||||
@@ -261,6 +265,7 @@ export async function Karlap() {
|
|||||||
h: 14
|
h: 14
|
||||||
})
|
})
|
||||||
|
|
||||||
|
form.updateFieldAppearances(pdfFont)
|
||||||
const pdfBytes = await doc.save()
|
const pdfBytes = await doc.save()
|
||||||
|
|
||||||
await fs.writeFile("karlap.pdf", pdfBytes)
|
await fs.writeFile("karlap.pdf", pdfBytes)
|
||||||
|
|||||||
Reference in New Issue
Block a user