C++を使用してHTMLをPDFに変換する方法

この例では、C++を使用してHTMLPDFに変換する方法を確認します。 HTMLからPDFへの変換は頻繁に必要とされる機能であり、C++で数行のコードを記述することで簡単に実現できます。

C++を使用してHTMLをPDFに変換する手順

  1. Aspose.Words.CppNuGetパッケージを使用する
  2. Aspose::Wordsと名前空間の保存への参照を含める
  3. 新しいDocument Classインスタンスを作成します
  4. Saveメソッドを使用してHTMlをC++でPDFに保存します

次の例では、外部依存関係がなく、いくつかの簡単な手順とコードで、C++を使用してHTMLをPDFに簡単にレンダリングできます。

C++を使用してHTMLをPDFに変換するコード

#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);
}
};

前の例では、C++でWord文書を作成する方法を学習しました。これで、C++でHTMLからPDFがどのようにレンダリングされるかを見てきました。この例では、Microsoftプラットフォームに依存することなく、Word文書の作成がはるかに簡単かつ迅速になります。

 日本語