في هذا المثال ، سنرى كيفية تحويل HTML إلى PDF باستخدام C ++. غالبًا ما تكون ميزة تحويل HTML إلى PDF مطلوبة ويمكنك تحقيق ذلك بسهولة عن طريق كتابة بضعة أسطر من التعليمات البرمجية في C ++.
خطوات تحويل HTML إلى PDF باستخدام C ++
- استخدم حزمة Aspose.Words.Cpp NuGet
- قم بتضمين مرجع إلى Aspose::Words وحفظ مساحات الأسماء
- قم بإنشاء مثيل Document Class جديد
- احفظ HTMl إلى PDF في C ++ باستخدام طريقة الحفظ
في المثال التالي ، يمكنك بسهولة تحويل HTML إلى PDF باستخدام C ++ بدون أي تبعيات خارجية وبضع خطوات بسيطة وتعليمات برمجية.
كود لتحويل HTML إلى PDF باستخدام C ++
#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); | |
} | |
}; |
في المثال السابق ، تعلمنا كيفية إنشاء مستند Word في C ++. الآن ، رأينا كيف يتم تقديم HTML إلى PDF في C ++. هذا المثال يجعل إنشاء مستند Word أسهل كثيرًا وأسرع مع عدم الاعتماد على نظام Microsoft الأساسي.