Convert Specific Page Range of Word DOC Document to PDF using C++ Code without using PageSplitter.cpp File

Hi,

I’m trying to convert word to pdf with Aspose.Words for C++ 20.7.
If I set page range, the result pdf will get broken format.
Looks like this:
err.word.original.png (59.9 KB)
err.pdf.out.png (115.0 KB)

Code is in Aspose.Words.Cpp_20.7\example\cpp\Loading-and-Saving\PageSplitter.cpp
Tested file is 《莫予毒也》故事梗概2020.9.2.doc.zip (8.3 KB)

@kngstr,

You can use following simple C++ code of Aspose.Words to save specific page range in Word DOC document to PDF without using PageSplitter.cpp:

#include <iostream>

#include <system/smart_ptr.h> // For System::MakeObject<T>()
#include <system/io/memory_stream.h>
#include <system/object_ext.h>
#include <system/io/file.h>

#include <Aspose.Words.Cpp/Licensing/License.h>
#include <Aspose.Words.Cpp/Model/Document/Document.h>
#include <Aspose.Words.Cpp/Model/Saving/PdfSaveOptions.h>

using namespace Aspose::Words;
using namespace Aspose::Words::Saving;

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

	// Initialize a Document.
	System::SharedPtr<Document> doc = System::MakeObject<Document>(u"C:\\Temp\\218036\\in.doc");

	System::SharedPtr<PdfSaveOptions> saveOptions = System::MakeObject<PdfSaveOptions>();
	// set page range 
	saveOptions->set_PageIndex(0); // Set the 0-based index of the first page to save
	saveOptions->set_PageCount(doc->get_PageCount()); // Set the total number of pages to save

	doc->Save(uR"(C:\temp\218036\\awcpp.pdf)", saveOptions);
}

@awais.hafeez

Thanks. I’ll try it.

@awais.hafeez

Thanks. It works fine.