Open IrishAdo opened 4 years ago
I have tested the write a pdf function and it is able to set the combo boxes correctly
var pdfFillForm = require('pdf-fill-form');
var fs = require('fs');
var sourceFilename = './write-pdf.pdf';
var targetFilename = './write-pdf-1.pdf';
var fields = {
'Given Name Text Box': 'Alfred',
'Family Name Text Box': 'Montique',
'Address 1 Text Box': 'Venice Beach',
'House nr Text Box': '10290',
'Address 2 Text Box': 'A sand dune',
'Postcode Text Box': '12345',
'City Text Box': 'Venice',
'Country Combo Box': 'Germany',
'Gender List Box': 'Woman',
'Height Formatted Field': '150',
'Driving License Check Box': true,
'Language 1 Check Box': false,
'Language 2 Check Box': true,
'Language 3 Check Box': false,
'Language 4 Check Box': true,
'Language 5 Check Box': false,
'Favourite Colour List Box': 'Orange'
};
pdfFillForm.write(
sourceFilename,
fields,
{ "save": "pdf", 'cores': 4, 'scale': 0.2, 'antialias': true }
)
.then(function(result) {
fs.writeFile(targetFilename, result, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
}, function(err) {
console.log(err);
});```
I think that section FormChoice on line 488 of NodePoppler.cc is missing a set value similar to the other types.
like line 283
Nan::Set(obj, Nan::New<String>("value").ToLocalChecked(), Nan::New<String>(((Poppler::FormFieldText *)field)->text().toStdString()).ToLocalChecked());
Sorry I don't know C to be any more help.
Line 367 is were the setting of the value is specified.
if (field->type() == Poppler::FormField::FormChoice) {
Poppler::FormFieldChoice *choiceField = (Poppler::FormFieldChoice *) field;
if (choiceField->isEditable()) {
choiceField->setEditChoice(QString::fromUtf8(params.fields.at(fieldName).c_str()));
}
else {
QStringList possibleChoices = choiceField->choices();
QString proposedChoice = QString::fromUtf8(params.fields.at(fieldName).c_str());
int index = possibleChoices.indexOf(proposedChoice);
if (index >= 0) {
QList<int> choiceList;
choiceList << index;
choiceField->setCurrentChoices(choiceList);
}
}
}
OK so I used this online pdf example to produce several test files
http://foersom.com/net/HowTo/data/OoPdfFormExample.pdf
quite simple you fill it in and save as and you have an example file to play with.
This is my test code
my test definition file just gives a list of test pdfs and a description of what I'm expecting here is the result for that pdf with everything filled in (NOTE if you open the saved PDF all fields are filled in correctly but the PDF forms can not get the values of the combo boxes)