यह दिलचस्प विषय C++** का उपयोग करके LaTeX को PNG को कैसे प्रस्तुत किया जाए, इस पर प्रदर्शन प्रदान करता है। हम LaTeX फ़ाइलों को .tex फ़ाइलें भी कहते हैं और कोई भी सरल API गुणों और विधियों के साथ C++ में PNG को LaTeX को आसानी से प्रस्तुत कर सकता है। इस उदाहरण का उपयोग करने के बारे में एक अच्छी बात यह है कि एपीआई कॉल उनके निष्पादन के लिए किसी अन्य एप्लिकेशन सॉफ़्टवेयर या तीसरे पक्ष के टूल पर निर्भर नहीं हैं।
सी++ का उपयोग करके लाटेक्स को पीएनजी में रेंडर करने के चरण
- NuGet पैकेज मैनेजर टूल का उपयोग करके Aspose.Tex.Cpp इंस्टॉल करें
- Aspose::TeX, Aspose::TeX::IO और Aspose::TeX::Presentation::Image namespaces का संदर्भ शामिल करें
- कॉन्फ़िगरेशन सेट करने के लिए TeXOptions Class ऑब्जेक्ट को इंस्टेंट करें
- LaTeX को PNG छवि में सहेजने के लिए PngSaveOptions Class ऑब्जेक्ट को त्वरित करें
- रेंडरिंग के लिए ImageDevice को इनिशियलाइज़ करें
- लाटेक्स को पीएनजी छवि में प्रस्तुत करने के लिए टेक्सजॉब का उपयोग करें
LaTeX दस्तावेज़ वैज्ञानिक और अनुसंधान उद्देश्य के लिए हैं जिनका उपयोग तकनीकी उपयोगकर्ताओं द्वारा किया जा सकता है और इसमें सादे पाठ के रूप में जानकारी होती है। C++* में पीएनजी इमेज में लाटेक्स एक्सपोर्ट करने के लिए, हम सबसे पहले इनपुट डायरेक्टरी, आउटपुट डायरेक्टरी और कंसोल ऑप्शंस से जुड़े कॉन्फिगरेशन सेट करने के लिए TeXOptions क्लास का एक इंस्टेंस बनाएंगे। बाद के चरणों में, हम छवि संकल्प जैसे PngSaveOptions गुण सेट करेंगे। अंत में, हम ImageDevice को इनिशियलाइज़ करेंगे और C++ का उपयोग करके TexJob *Render LaTeX से PNG इमेज को इनिशियलाइज़ करेंगे।
सी++ में लाटेक्स को पीएनजी में बदलने के लिए कोड
#pragma once | |
#include <system/text/encoding.h> | |
#include <system/io/text_writer.h> | |
#include <system/io/memory_stream.h> | |
#include <system/array.h> | |
#include <Aspose.TeX.Cpp/TeXOptions.h> | |
#include <Aspose.TeX.Cpp/TeXConfig.h> | |
#include <Aspose.TeX.Cpp/TeXJob.h> | |
#include <Aspose.TeX.Cpp/Presentation/SaveOptions.h> | |
#include <Aspose.TeX.Cpp/Presentation/Image/PngSaveOptions.h> | |
#include <Aspose.TeX.Cpp/Presentation/Image/ImageDevice.h> | |
#include <Aspose.TeX.Cpp/IO/OutputFileSystemDirectory.h> | |
#include <Aspose.TeX.Cpp/IO/OutputConsoleTerminal.h> | |
#include <Aspose.TeX.Cpp/IO/IOutputWorkingDirectory.h> | |
#include <Aspose.TeX.Cpp/IO/IOutputTerminal.h> | |
#include <Aspose.TeX.Cpp/IO/InputFileSystemDirectory.h> | |
#include <Aspose.TeX.Cpp/IO/InputConsoleTerminal.h> | |
#include <Aspose.TeX.Cpp/IO/IInputTerminal.h> | |
#include <cstdint> | |
#include <Aspose.TeX.Cpp/License.h> | |
using namespace Aspose::TeX; | |
using namespace Aspose::TeX::IO; | |
using namespace Aspose::TeX::Presentation::Image; | |
class TexToPngConverter{ | |
public: | |
static void TexToPNGRendering() | |
{ | |
// Initialize license object | |
System::SharedPtr<License> TexLicense = System::MakeObject<License>(); | |
// Applying license for rendering PNG | |
TexLicense->SetLicense(u"Aspose.Total.NET.lic"); | |
// Instantiate TeXOptions object for configuring settings | |
System::SharedPtr<TeXOptions> RenderingOptions = TeXOptions::ConsoleAppOptions(TeXConfig::ObjectTeX()); | |
// Specify the job name. | |
RenderingOptions->set_JobName(u"stream-image-out"); | |
// Specify the input file working directory. | |
RenderingOptions->set_InputWorkingDirectory(System::MakeObject<InputFileSystemDirectory>(u"")); | |
// Specify the output file working directory. | |
RenderingOptions->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(u"")); | |
// Setting the console input terminal | |
RenderingOptions->set_TerminalIn(System::MakeObject<InputConsoleTerminal>()); | |
// Setting the console output terminal | |
RenderingOptions->set_TerminalOut(System::MakeObject<OutputConsoleTerminal>()); | |
// Creating and specifying PngSaveOptions | |
System::SharedPtr<PngSaveOptions> ImageOptions = System::MakeObject<PngSaveOptions>(); | |
ImageOptions->set_Resolution(300); | |
RenderingOptions->set_SaveOptions(ImageOptions); | |
// Instantiating ImageDevice for rendering | |
System::SharedPtr<ImageDevice> ImageDevise = System::MakeObject<ImageDevice>(); | |
// Running TexJob for rendering to PNG | |
TeXJob::TeXJob(System::MakeObject<System::IO::MemoryStream>(System::Text::Encoding::get_ASCII()-> | |
GetBytes(u"\\hrule height 10pt width 95pt\\vskip10pt\\hrule height 5pt")), | |
ImageDevise, RenderingOptions); | |
// During executoion, when the console prompts the input, | |
// Step 1: Type "ABC", press Enter | |
// Step 2: Type "\end" and press Enter again | |
// In order to view the ouptut and to look write. | |
RenderingOptions->get_TerminalOut()->get_Writer()->WriteLine(); | |
// Alternatively, you can also get the images in form of array of byte arrays | |
// The 0th index belong to first page. | |
System::ArrayPtr<System::ArrayPtr<uint8_t>> result = ImageDevise->get_Result(); | |
} | |
}; |
इस विषय में, हमने सीखा है कि कैसे C++ सरल API कॉल का उपयोग करके LaTeX से PNG इमेज बनाता है। यदि आप एमपीपी फाइलों को प्रस्तुत करने जैसी अन्य विशेषताओं को सीखने में रुचि रखते हैं तो C++ का उपयोग करके MPP को XPS में कैसे बदलें? पर लेख देखें।