Replies: 2 comments
-
You'll want to look at the PDFTextField.acroField.DA: textField.acroField.DA()
textField.acroField.setDefaultAppearance(`<DA string>`) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Have you actually tried it? Because I've solved this problem in the meantime and I'm 100% confident this is not the solution. const file = 'path-to-pdf-file.pdf'
const pdfDoc = await PDFDocument.load(fs.readFileSync(file));
pdfDoc.registerFontkit(fontkit);
// This can be guessed or known by looking at all fields of type fonts
const refNumber = 111;
const embededFontRef = pdfDoc.context.lookup(
PDFRef.of(refNumber, 0),
PDFStream,
);
// Some fonts need to be inflated, others not, to yield the font bytes
const fontBytes = pako.inflate((embededFontRef as PDFRawStream).contents);
const embededFont = await pdfDoc.embedFont(fontBytes);
const form = pdfDoc.getForm();
const field = form.getTextField('Field');
field.setText('The quick brown dog jumps over the lazy fox');
// You have to updateAppearances with the font so that the DefaultAppearance gets changed
field.updateAppearances(embededFont);
const pdfBytes = await pdfDoc.save(); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I have a PDF with some pre-existing embeded fonts. I have to first say that I don't know the PDF standard very well but I'm trying to guess how it behaves.
pdf-lib
, the behavior is the same as with Preview: default font. I haven't done the font manipulation technique from the docs as the fonts are already embeded.From this I suspect that:
pdf-lib
does not support itIs this a missing feature or am I misunderstanding the situation?
Cheers
Beta Was this translation helpful? Give feedback.
All reactions