We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Set Encoding, Compatibility Options, Orientation then Convert HTML to Word DOCX File | C++

Hi,

SDK: Words for C++ 21.6
NPI_DQE_PE_项目工程师 - 副本.zip (8.1 KB)

Thanks

@kngstr,

We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-22535. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

@kngstr,

Regarding WORDSNET-22535, we suggest you to please try running the following code of Aspose.Words for C++ API on your end:

#include <system/io/file.h>

#include <Aspose.Words.Cpp/Licensing/License.h>
#include <Aspose.Words.Cpp/Model/Document/Document.h>
#include <Aspose.Words.Cpp/Loading/LoadOptions.h>
#include <Aspose.Words.Cpp/Section.h>
#include <Aspose.Words.Cpp/PageSetup.h>
#include <Aspose.Words.Cpp/Settings/CompatibilityOptions.h>

using namespace Aspose::Words;
using namespace Aspose::Words::Loading;

int main()
{
	System::SharedPtr<License> license = System::MakeObject<License>();
	System::SharedPtr<System::IO::Stream> stream = System::IO::File::OpenRead(u"C:\\Temp\\Aspose.Words.CPP.lic");
	license->SetLicense(stream);

	System::SharedPtr<LoadOptions> loadOptions = System::MakeObject<LoadOptions>();
	loadOptions->set_Encoding(System::Text::Encoding::GetEncoding(u"GB2312"));

	System::SharedPtr<Document> doc = System::MakeObject<Document>(u"C:\\Temp\\232779\\in.html", loadOptions);

	doc->get_CompatibilityOptions()->set_GrowAutofit(true);
	doc->get_CompatibilityOptions()->set_DoNotUseEastAsianBreakRules(true);
	doc->get_CompatibilityOptions()->set_DoNotSnapToGridInCell(true);
	doc->get_CompatibilityOptions()->set_DoNotWrapTextWithPunct(true);
	doc->get_CompatibilityOptions()->set_UseFELayout(true);

	doc->get_FirstSection()->get_PageSetup()->set_Orientation(Aspose::Words::Orientation::Landscape);
	doc->get_FirstSection()->get_PageSetup()->set_LeftMargin(36);

	doc->Save(uR"(C:\\temp\\232779\\awcpp-21.7 new.docx)");
}

@awais.hafeez

Thanks.
It works well.

Another question, how can I deal with this html.
pre样本.zip (1.3 KB)

@kngstr,

I have converted the HTML file from your post to DOCX format by using the code from my previous post and attach the Word file here for your reference (see HTML to Word by Aspose.Words CPP 21.7.docx (9.7 KB)). Do you still observe problems in this output DOCX? If yes, then please also provide a comparison screenshot highlighting (encircle) the problematic areas in this Aspose.Words 21.7 generated output DOCX.

@awais.hafeez

Thanks.
I do test with your prvious post code.
Just wondering if it’s can be better.

@kngstr,

If the output attached in my previous post is not acceptable for you then can you please also provide a comparison screenshot highlighting (encircle) the problematic areas in Aspose.Words 21.7 generated output DOCX? We will then investigate the issue further on our end and provide you more information.

@awais.hafeez

doc->get_FirstSection()->get_PageSetup()->set_Orientation(Aspose::Words::Orientation::Landscape);

This is not good.
It will be much better if it can automatically fit page size.

@kngstr,

I have logged these details in our issue tracking system and will keep you posted here on any further updates.

@kngstr,

Can you please clarify a bit more what is “not good” in this document set after import from HTML? Please also provide a comparison screenshot highlighting (encircle) the problematic areas in Aspose.Words 21.8 generated output DOCX? We will then investigate the issue further on our end and provide you more information.

@awais.hafeez

It will be much better if sdk can automatically fit page size.
You can compare with the output pdf which is saved by chrome.

@kngstr,

We have logged these concerns in our issue tracking system and will keep you posted here on further updates.

@kngstr,

We have checked and it seems that Aspsoe.Words’ output and web browser’s screen are quite similar. Please see screenshot: 2021-08-24_17-08-36.png (247.2 KB)