Hello,
I’m having some problems with aspose.pdf. We have a template where we replace the text based in placeholders, like, {{name}}, we search for this in a PDF, and we replace with the proper value. But, the result is that the characters following the first capital letter are overriding it.
I put an example in the image below
image.png (63.9 KB)
Do you have any advice on how to fix it?
We’re using the last version of Aspose.PDF 24.8.
Thank you a lot!
@marcoolimpio
Please attach the document and code you are using.
Hello @sergei.shibanov
the code
public async Task<Stream> GenererDocumentPdf(Stream stream, IEnumerable<KeyValuePair<string, string>> valeurs)
{
Stream streamcopie = new MemoryStream();
await stream.CopyToAsync(streamcopie);
Document document = new(streamcopie);
streamcopie.Seek(0, SeekOrigin.Begin);
foreach (var valeur in valeurs)
{
TextFragmentAbsorber textFragmentAbsorber = new("{{" + valeur.Key + "}}");
document.Pages.Accept(textFragmentAbsorber);
var textsFragmentsAbsorbers = textFragmentAbsorber.TextFragments;
foreach (var textFragment in textsFragmentsAbsorbers)
{
textFragment.Text = valeur.Value;
}
}
MemoryStream memoryStream = new();
document.Save(memoryStream, SaveFormat.Pdf);
memoryStream.Seek(0, SeekOrigin.Begin);
streamcopie.Close();
return memoryStream;
}
The file
ResultatDunePlainte.pdf (147.5 KB)
Thank you!
@marcoolimpio
I tried to reproduce the problem using the code below in .Net 6 with the library version 24.09 and got a valid result.
ResultatDunePlainte-changed.pdf (257.6 KB)
Document document = new(dataDir + "ResultatDunePlainte.pdf");
var values = new Dictionary<string, string>()
{
{ "Prenoms", "Сhanged" },
{ "Non", "Сng" },
{ "Courriel", "Something" },
{ "Adrsesse", "Here Adr" }
};
foreach (var item in values)
{
var textFragmentAbsorber = new TextFragmentAbsorber("{{" + item.Key + "}}");
document.Pages.Accept(textFragmentAbsorber);
var textsFragmentsAbsorbers = textFragmentAbsorber.TextFragments;
foreach (var textFragment in textsFragmentsAbsorbers)
{
textFragment.Text = item.Value;
}
}
document.Save(dataDir + "ResultatDunePlainte-changed.pdf");
Please tell me how to reproduce this problem.
Interesting. The template file does not have a Times New Roman font but it changes to it. I’ ve noticed that it happens with some chars, like the one of the first image like ‘O’, ‘Q’, ‘z’ with the font of the document.
Examples with the same code extract and document
image.png (5.7 KB)
image.png (5.7 KB)
The fields utilized
{
"Prenoms": "OOOOOOOOOOOlimpio",
"Non": "zidane Olimpio Oliveira Zinedine",
"Courriel": email@justice.gouv.qc.ca,
"Adrsesse": "1111, Boulevard du Versant-Nord Ouest",
"Appartement": "",
"Ville":"Québec",
"Province":"Québec",
"CodePostal":"G1V-1A3",
"Pays":"Canada",
"InformationsPlainte":"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"NomJuge":"Juge Marco Olimpio Oliver",
"TribunalJuge":"zirof Olivaras Juge Marco Olimpizes e Olivier",
"NumeroDossier":"500-14-000001-241",
"DateFaits":"2024-01-01",
"MotifPlainte":"Quelqu'un a mangé mon fromage!ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz"
}
Exemple of generated file
ResultatDunePlainte (8).pdf (347.9 KB)
Thank you @sergei.shibanov ! Have a good day
The fonts utilized
image.png (290.6 KB)
We’re using .net8
Thanks
@marcoolimpio
The problem was reproduced with the data you provided.
I have created a task for the development team.
@marcoolimpio
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-58226
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Hello @sergei.shibanov! We have the license for ASPOSE.Total. I’m not responsible for the licenses. Does it mean that we have access to the ‘Paid Support Service’ or we’re speaking of two different things?
@marcoolimpio
Tasks are assigned three main priorities. The lowest for users without a license, normal for users who have purchased a license, and the highest for users who have purchased paid support.
I don’t see whether you have a license. You probably registered with a different e-mail. Therefore, in the created task, I cannot mark that it was created by a client with a license.