Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active February 3, 2022 01:15
How to Convert HTML to PDF using C++. For more details, please refer to topic: https://kb.aspose.com/words/cpp/how-to-convert-html-to-pdf-using-cpp/
#include <Aspose.Words.Cpp/Document.h>
#include <Aspose.Words.Cpp/DocumentBuilder.h>
#include <Aspose.Words.Cpp/Saving/DocSaveOptions.h>
#include <Aspose.Words.Cpp/Saving/SaveOutputParameters.h>
#include <system/io/file.h>
#include <Aspose.Words.Cpp/License.h>
using System::ArrayPtr;
using System::MakeArray;
using System::MakeObject;
using System::SharedPtr;
using System::String;
using namespace Aspose::Words;
using namespace Aspose::Words::Saving;
class HtmlToPdfConvertor
{
public:
void HtmlToPdfConversion()
{
// File name and path of license file
System::String testLicenseFileName = u"Aspose.Total.NET.lic";
// Setting the Aspose.Words before creating Word document
SharedPtr<License> wordsLicense = System::MakeObject<License>();
// Setting license
wordsLicense->SetLicense(testLicenseFileName);
// Create an instance of Document class of Aspose.Words for C++
// to load the HTML file
SharedPtr<Document> WordDocumentUsingCPP = MakeObject<Document>(u"HtmlFile.html");
// Save HTML to PDF in C++ using Save method
WordDocumentUsingCPP->Save(u"Html_To_PDF_using_CPP.pdf", SaveFormat::Pdf);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment