出力を ZIP に書き込む
C++ を介して TeX ファイル変換の結果を ZIP として保存する
TeX はデータ マークアップ言語であり、出版セット システムとしても知られるコンピューター組版システムのコアです。ファイル形式と呼ばれることが多いですが、実際には、数学的、技術的、およびその他の複雑なドキュメントを作成するために使用されるプログラミング言語およびインタープリター エンジンです。ただし、ファイルが作成された後は、どのデバイスやプラットフォームでも結果を使用できるように、より一般的な形式に変換する必要がある場合があります。
Aspose.TeX API ソリューションは、TeX ファイルを変換し、結果を ZIP アーカイブとして保存する機能を提供します。ここに提供されているコード スニペットは、TeX ファイルを PDF に変換し、出力を zip ファイルとして保存する方法を示しています。API コンバーターは C++ 言語で TeX ファイルを変換でき、クロスプラットフォーム アプリケーションの作成や C++ プロジェクトへの統合に使用できます。
例を実行するには、C++ プラットフォーム向けの機能豊富で使いやすいドキュメント操作および変換ツールである Aspose.TeX for C++ API が必要です。Aspose.TeX API は、NuGet パッケージ マネージャーで検索するか、パッケージ マネージャー コンソールで Install-Package Aspose.TeX コマンドを使用してインストールできます。
Package Manager Console Command
PM> Install-Package Aspose.TeX
ここにあるコードは、TeX ファイルを変換し、ZIP アーカイブ内の PDF として保存しています。このような変換を処理するには、次の手順を実行します。
- TeXOptions クラスのインスタンスを作成します。これを使用して、OutputWorkingDirectory プロパティを使用して出力用の ZIP アーカイブ作業ディレクトリを指定します。
- OutputConsoleTerminal クラスを使用して、コンソールを出力ターミナルとして指定します。
- PdfSaveOptions クラスを使用して、出力を保存するためのオプションを定義します。
- PdfDevice 用の TeXJob メソッドを使用して、TeX から PDF への変換を実行します。
- 出力を調整します。
- OutputZipDirectory クラスを使用して、出力 ZIP アーカイブを完成させます。コードでは、プロセス中に発生する可能性のある例外を処理するために try-catch ブロックを使用しています。
出力に ZIP ディレクトリを使用するための C++ コード
using Aspose::TeX::IO;
using Aspose::TeX::Presentation::Pdf;
using System::IO; // Open a stream on a ZIP archive that will serve as the input working directory.
{
System::SharedPtr<System::IO::Stream> inZipStream = System::IO::File::Open(System::IO::Path::Combine(RunExamples::InputDirectory, u"zip-in.zip"), System::IO::FileMode::Open);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_1({ inZipStream});
// ------------------------------------------
try{
System::SharedPtr<System::IO::Stream> outZipStream = System::IO::File::Open(System::IO::Path::Combine(RunExamples::OutputDirectory, u"zip-pdf-out.zip"), System::IO::FileMode::Create);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_0({ outZipStream});
// ------------------------------------------
try
{
// Create typesetting options for default ObjectTeX format on ObjectTeX engine extension.
System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::ObjectTeX());
// Specify a ZIP archive working directory for the input.
options->set_InputWorkingDirectory(System::MakeObject<InputZipDirectory>(inZipStream, u"in"));
// Specify a ZIP archive working directory for the output.
options->set_OutputWorkingDirectory(System::MakeObject<OutputZipDirectory>(outZipStream));
// Specify the console as an output terminal.
options->set_TerminalOut(System::MakeObject<OutputConsoleTerminal>());
// Default. Not necessary to specify.
// Create and specify saving options.
options->set_SaveOptions(System::MakeObject<PdfSaveOptions>());
// Run typesetting.
Aspose::TeX::TeX::Typeset(u"hello-world", System::MakeObject<PdfDevice>(), options);
// For the consequent output to look right.
options->get_TerminalOut()->get_Writer()->WriteLine();
// Finalize the output ZIP archive.
(System::DynamicCast<Aspose::TeX::IO::OutputZipDirectory>(options->get_OutputWorkingDirectory()))->Finish();
}
catch(...)
{
__dispose_guard_0.SetCurrentException(std::current_exception());
}
}
catch(...)
{
__dispose_guard_1.SetCurrentException(std::current_exception());
}
}TeX TeX ファイル形式とは
TeX は高品質な組版システムで、プログラミング言語でもあり、TeX エンジン(pdfTeX、XeTeX、LuaTeX など)で処理して PDF や DVI などの出力を生成します。