Hello Gabriel,
thanks for pointing me to this solution. It's working well for static files.
I played a bit around to see if it's possible to do an easy implementation to access the files uploaded through the files input field. Luckily I found an easy approach. Maybe you can add it to the main code. 🙂 (Not sure if that's the right way of sharing.)
Add the following code to form.js
:
import {
...
getAttributeFileHref
} from './shared/attribute.js';
...
...
// helpers
exposedFunctions:(s) => {
return {
...
get_field_file_link:(fieldId, fileMeta) => s.fieldIdMapData[fieldId] === undefined
? undefined : s.getAttributeFileHref(s.fieldIdMapData[fieldId].attributeId, fileMeta.id, fileMeta.name, s.token),
...
}
...
...
methods:{
// externals
...
getAttributeFileHref,
...
// form management
...
}
and in builderJsFunction.js
the method names have to be added to placeholdersSet
and placeholdersUnset
methods.
The same could also be done for getAttributeFileVersionHref
method to create a link for a specific file version.
In a frontend function you can now use the following code to receive an uploaded file (picture) to add it to a pdf:
let fm_img = app.get_field_value({F17: 0 test14_pdf.pictures});
let rel_src = app.get_field_file_link({F17: 0 test14_pdf.pictures}, fm_img[0]);
rel_src = rel_src..slice(1); // cut off leading slash
let image= "<div><img src='" + rel_src + "'/></div>";
app.pdf_create(app.get_field_value({F2: 0 test14_pdf.file_name}), 'a4', 'p',
app.get_field_value({F4: 0 test14_pdf.margin_x}),
app.get_field_value({F6: 0 test14_pdf.margin_y}),
app.get_field_value({F15: 0 test14_pdf.html_header}),
image + app.get_field_value({F12: 0 test14_pdf.html_body}),
app.get_field_value({F16: 0 test14_pdf.html_footer}),
app.get_field_value({F13: 0 test14_pdf.css_styles})
);
BR
Thomas