Problems with accent characters in Aspose.Words C++

Hi.
I’m trying to use Aspone.Words for evaluate his funcionality.
I’ve created a minimal program to test how to create a simple word document.
I’ve problems when I use accent or special spanish characters (á, é, Ñ, ñ … etc)
Chars are showed incorrectly. If I use accent characters in file name to save it, I’ve the same problem.

Here is my brief code:

System::SharedPtr<LoadOptions> loadOptions = System::MakeObject<LoadOptions>();

System::SharedPtr<Document> doc = System::MakeObject<Document>();

System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc, loadOptions);

builder->MoveToDocumentStart();

builder->Write(u"Hello World Ñ á Á");

doc->Save(u"C:\\Temp\\Tomás.docx");

I have also tried reading and modifying an existing word file:

System::String sampleFile1 = u"C:\\temp\\accent.docx";
 
auto loadOptions = MakeObject<LoadOptions>();
loadOptions->get_LanguagePreferences()->set_DefaultEditingLanguage(EditingLanguage::SpanishSpainModernSort);

 auto lang = loadOptions->get_LanguagePreferences()->get_DefaultEditingLanguage();

lang variable take the correct value (SpanishSpainModernSort (3082)), but I get the same wrong result.

I’m ussing Visual Studio 2022 C++

Best regards.

@tcabezudo Unfortunately, I cannot reproduce the problem on my side. Using the following code:

auto doc = System::MakeObject<Document>();
auto builder = System::MakeObject<DocumentBuilder>(doc);
builder->MoveToDocumentStart();
builder->Write(u"Hello World Ñ á Á");
doc->Save(u"C:\\Temp\\Tomás.docx");

Here is the produced output: Tomás.docx (7.0 KB)

I have used the latest 23.9 version for testing.

Thanks Alexey.

I’m using 23.7 version…

I’m going to try version 23.9…

Best regards.

1 Like

Hi again Alexey.

I have finally managed to get accented characters to be generated correctly when writing a Word document. Surely the problem was using the demo version without a license. When I have purchased the license and used it within the program, the generation of the Word file already works correctly. Now the problem is when saving as a PDF document: Problems with accented characters persist in PDF…

 // Save the output as PDF
 doc->Save(u"C:\\Temp\\Tomás.pdf");

Best regards.

@tcabezudo Unfortunately, I cannot reproduce the problem on my side. I have used exactly the same code for testing:

auto doc = System::MakeObject<Document>();
auto builder = System::MakeObject<DocumentBuilder>(doc);
builder->MoveToDocumentStart();
builder->Write(u"Hello World Ñ á Á");
doc->Save(u"C:\\Temp\\Tomás.pdf");

The output PDF document is produced properly: Tomás.pdf (18.5 KB)

Accent characters looks fine in both file name and in the PDF content.

I doubt that the problem is caused by using demo version. The evaluation version of Aspose.Words provides exactly the same functionality as the licensed version and has only two limitations:

  • injects an evaluation version watermark into the document
  • limits the maximum size of the processed document to several hundreds of paragraphs.

Ok Alexey…

Possibly some setting is missing… I’ll continue investigating.

Thanks.

You’re rigth, Alexey. The problem is not the license… I said that the problem was solved, but surely I were wrog. So many output versions of Word files… Maybe the correct word file was the your one…
My last try was reinstalation of ASPOSE.Word API Librarys trougth NuGet, but unsuccessful…
Anyway, I keep have same problem. I don’t know what to try now.
The short code snippet is as follows:

#include <iostream>

#include <Aspose.Words.Cpp/Document.h>
#include <Aspose.Words.Cpp/DocumentBuilder.h>

using System::MakeObject;
using namespace Aspose::Words;
using namespace Aspose::Words::Saving;

int main()
{
  // Create a blank document.
  System::SharedPtr<Document> doc = System::MakeObject<Document>();

  // DocumentBuilder provides members to easily add content to a document.
  System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc);

  // Insert text to the document A start
  builder->MoveToDocumentStart();
  builder->Write(u"Hello World Ñ á Á");

  // // Save the output.
  doc->Save(u"C:\\Temp\\Tomás.docx");
  return 0;
}

As you can see, minimal header files and namespace declarations…

I have tried to generate code as a static or dynamic library… with the same result.

Please, could you send me a compressed file with your working solution files (.sln, .vcxproj, …) of Visual Studio for this short example to see what settings I may be using incorrectly? Logically I would change the access paths to the ASPOSE libraries, but I would have something to investigate.

I’m using Windows 10 Pro 22H2. Visual Studio 2022 Ver. 17.7.4
ASPOSE.Word cpp 23.9

Thanks in advance…

@tcabezudo
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): WORDSCPP-1253

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.

@tcabezudo We have completed analysis of the issue and concluded to close it as not a bug. The problem is probably in file encoding. Have you tried adding the /utf-8 compile flag - this solved the problem on our side.

Hi Alexey.

Indeed, the problem was related to character encoding. I’ve used std::wstring instead of std::string and I’ve been able to solve the problems.

Thanks!

1 Like