C++를 사용하여 LaTeX를 PNG로 렌더링하는 방법

이 흥미로운 주제에서는 C++**를 사용하여 **LaTeXPNG로 **렌더링하는 방법에 대한 데모를 제공합니다. 또한 LaTeX 파일을 .tex 파일로 부르며 간단한 API 속성과 메서드를 사용하여 LaTeX를 C++에서 PNG로 쉽게 렌더링할 수 있습니다. 이 예제를 사용할 때 한 가지 좋은 점은 API 호출이 실행을 위해 다른 애플리케이션 소프트웨어나 타사 도구에 의존하지 않는다는 것입니다.

C++를 사용하여 LaTeX를 PNG로 렌더링하는 단계

  1. NuGet 패키지 관리자 도구를 사용하여 Aspose.Tex.Cpp 설치
  2. Aspose::TeX, Aspose::TeX::IO 및 Aspose::TeX::Presentation::Image 네임스페이스에 대한 참조 포함
  3. 구성 설정을 위한 TeXOptions Class 개체 인스턴스화
  4. LaTeX를 PNG 이미지로 저장하기 위한 PngSaveOptions Class 개체 인스턴스화
  5. 렌더링을 위해 ImageDevice 초기화
  6. LaTeX를 PNG 이미지로 렌더링하기 위해 TexJob 사용

LaTeX 문서는 기술 사용자가 사용할 수 있고 일반 텍스트 형식의 정보를 포함하는 과학 및 연구 목적을 위한 것입니다. C++*에서 LaTeX를 PNG 이미지로 내보내기 위해 먼저 입력 디렉토리, 출력 디렉토리 및 콘솔 옵션과 관련된 구성을 설정하기 위한 TeXOptions 클래스의 인스턴스를 생성합니다. 후속 단계에서는 이미지 해상도와 같은 PngSaveOptions 속성을 설정합니다. 마지막으로 ImageDevice를 초기화하고 TexJob을 사용하여 *C++*를 사용하여 LaTeX를 PNG 이미지로 렌더링합니다.

C++에서 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 이미지를 만드는 방법을 배웠습니다. MPP 파일 렌더링과 같은 다른 기능에 대해 알아보려면 C++를 사용하여 MPP를 XPS로 변환하는 방법에 대한 문서를 참조하세요.

 한국인