Open krzyswiatkowski opened 3 years ago
Would you please share a file that can be used to reproduce the issue?
Hey @Hopding sorry for delayed response. I'm attaching ZIP archive with 5 files in it:
example-single-field.pdf
- this is the template which should be used to fill text-fieldpdf-test.js
- JS file which allowed me to reproduce the issue (you might be interested in comments inside)example-single-field-NOTflatten.pdf
- result file when I DID NOT use form.flatten() methodexample-single-field-flatten.pdf
- result file when I used form.flatten() method before saving the docubuntu-font.ttf
- font used in exampleSo it looks like not the setText
method is responsible for removing the border of combed fields - flatten
method is.
Edit: Versions of the packages I've used:
pdf-lib: 1.17.0
@pdf-lib/fontkit: 1.1.1
node: v14.15.5
npm: 6.14.11
I have tested your shown example - it's worked. Here my example code.
const {PDFDocument} = require('pdf-lib');
const fontkit = require('@pdf-lib/fontkit');
const fs = require('fs');
const ubuntuFontBytes = fs.readFileSync('ubuntu-font.ttf');
async function runTest() {
var templ= 'example-single-field.pdf';
const pdfDoc = await PDFDocument.load(fs.readFileSync(templ));
pdfDoc.registerFontkit(fontkit);
const font = await pdfDoc.embedFont(ubuntuFontBytes);
const form = pdfDoc.getForm();
const combedField = form.getTextField('combedField');
//console.log('Text field contents:', combedField.getText);
//if (combedField.isCombed()) console.log('Combing is enabled');
combedField.setText('Filled by script');
//console.log("-2-" +combedField.isCombed());
const [ widget ]= combedField.acroField.getWidgets();
//console.log("W:::"+widget.getOrCreateBorderStyle);
widget.getOrCreateBorderStyle().setWidth(1); // trying to restore border
combedField.enableCombing(); // trying to restore combing
combedField.updateAppearances(font); // trying to force update appearance
form.updateFieldAppearances(this.font);
form.flatten({ updateFieldAppearances: true });
const fillpdfBytes = await pdfDoc.save({ useObjectStreams: true });
fs.writeFileSync('test.pdf', fillpdfBytes); //await pdfDoc.save());
}
runTest();
@krzyswiatkowski thanks for sharing the files! I'll dig into this when I get a chance 👍
What were you trying to do?
Trying to use
pdfTextField.setText
method to fill pdf-form-field and leave combing & border visibleI have PDF file with prepared form in it. Most of text-fields in this PDF-file has combing & border visible. I want to fill those fields using
setText
method and leave combing & border visible.Why were you trying to do this?
I want to fill fields inside pdf-form and leave combing & border visible (border-boxes for letters).
How did you attempt to do it?
Example of how I'm filling the field and how I've tried to restore combing &border after calling setText:
What actually happened?
After using
setText
method, particular field loses combing & border. setting additonal border doesn't help. callingenableCombing
doesn't help.What did you expect to happen?
after using
setText
combing with border are still present particular field.How can we reproduce the issue?
setText
methodVersion
1.17.0
What environment are you running pdf-lib in?
Node
Required Reading
Additional Notes
No response