Hello ,
I need please your support for that : Date & text always displayed in english with function CardText even we define the language to french in our template !
Could you please help!
Thanks!
Hello ,
I need please your support for that : Date & text always displayed in english with function CardText even we define the language to french in our template !
Could you please help!
Thanks!
Pouvez-vous préciser comment vous définissez la langue dans votre modèle et comment vous utilisez la fonction CardText ?
@MDAKNOU By default Aspose.Words uses the current thread’s locale to update fields. So you should either specify the thread’s locale using the following code:
// Set locale for the current thread.
Locale current = CurrentThreadSettings.getLocale();
CurrentThreadSettings.setLocale(Locale.forLanguageTag("de-DE"));
Document doc = new Document("C:\\Temp\\in.docx");
doc.save("C:\\Temp\\out.pdf");
// Restore locale.
CurrentThreadSettings.setLocale(current);
Or instruct Aspose.Words to use field code as field update culture source:
Document doc = new Document("C:\\Temp\\in.docx");
doc.getFieldOptions().setFieldUpdateCultureSource(FieldUpdateCultureSource.FIELD_CODE);
doc.save("C:\\Temp\\out.pdf");
Thanks for your reply!
But i want that the language is dynamic means depend what is used as language in the template word.
The use of this :
Document doc = new Document("C:\\Temp\\in.docx");
doc.getFieldOptions().setFieldUpdateCultureSource(FieldUpdateCultureSource.FIELD_CODE);
doc.save("C:\\Temp\\out.pdf");
Can render it dynamic (depending on the language used in template) ?
@MDAKNOU Yes, this code does exactly this. Aspose.Words uses the culture set in the field to format the field’s value.
Ok thanks! will test it and let you know.
heloo un petit test
To add the issue is with the 2 merge fields:
projectEndDate & bondAmount
@MDAKNOU As I can see everything works as expected. I used the following simple code for testing:
Document doc = new Document("C:\\Temp\\in.docx");
doc.getFieldOptions().setFieldUpdateCultureSource(FieldUpdateCultureSource.FIELD_CODE);
String[] names = new String[] { "projectStartDate", "projectEndDate", "bondAmount" };
Object[] values = new Object[] { new Date(), new Date(), 101 };
doc.getMailMerge().execute(names, values);
doc.save("C:\\Temp\\out.docx");
The output is the following:
• Montant du contrat : 101 EUR (cent un EURO) TTC
• Date de commencement des travaux : 30 janvier 2025
• Date de réception prévue : 30 janvier 2025
Both dates and bondAmount with DardText
switch are in French. Here is the output:
out.docx (5.5 MB)
Hello @alexey.noskov ,
I have a question about dealing with image in aspose :
When i use this case it generate as well the pdf with the correct image :
{
"templateId": "{{templateId}}",
"fields": [
{
"fieldName": "BASE_64_LOGO_1",
"fieldValue" : "value"
"typeCode": "QR_CODE"
}
]
}
But when I use this case doesn’t fonctionne as expected :
{
"templateId": "{{templateId}}",
"fields": [
{
"fieldName": "QR_CODE_LOGO_1",
"fieldValue" : "value"
"typeCode": "QR_CODE"
}
]
}
My question is : the field name to generate correctly the image for aspose should it start only with BASE_64_X
??
Thanks for your help!
@MDAKNOU Unfortunately, it is not quite clear how you pass these data into the document. If possible, could you please provide a simple code example that will allow us to reproduce the problem? We will check the issue and provide you more information.
yes i have this 2 cases of conditions:
if (args.getDocumentFieldName().startsWith(QR_CODE_PREFIX) && args.getFieldValue() != null ) {
LOGGER.info("QR CODE LOADING");
documentBuilder.moveToMergeField(args.getDocumentFieldName());
var decodedBase64Value = generateQRCodeService.generateQrCode(args.getFieldValue().toString());
documentBuilder.insertImage(decodedBase64Value);
}
// ------ Base64 image Handling --------
// base64 values are output as image fields
if (args.getDocumentFieldName().startsWith(BASE_64_PREFIX) && args.getFieldValue() != null) {
documentBuilder.moveToMergeField(args.getFieldName());
// add the image bytes
var decodedBase64Value = Base64.getDecoder().decode(args.getFieldValue().toString());
documentBuilder.insertImage(decodedBase64Value);
}
For the first case (QR_CODE_PREFIX) : args.getFieldValue() will be a text (web link) , will call generateQRCodeService.generateQrCode to get The QR Code as an imagebase 64 .
The second case (BASE_64_PREFIX) : args.getFieldValue() will be a text(encoded image) , that we will just encode then and insert it in the document builder
@MDAKNOU Answered in another your thread:
https://forum.aspose.com/t/generate-base-64-image-from-template-in-pdf/309240/7