Last active
June 22, 2021 12:42
-
-
Save aspose-com-gists/a520bd27ea4617951b3cc55b1dc2748e to your computer and use it in GitHub Desktop.
Convert TeX to PDF or XPS File Programmatically using C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Convert TeX to PDF or XPS File Programmatically using C++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create typesetting options for default ObjectTeX format on ObjectTeX engine extension. | |
System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::ObjectTeX()); | |
// Specify a file system working directory for input. | |
options->set_InputWorkingDirectory(System::MakeObject<InputFileSystemDirectory>(u"SourceDirectory")); | |
// Specify a file system working directory for output. | |
options->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(u"OutputDirectory")); | |
// Specify console as output terminal. | |
options->set_TerminalOut(System::MakeObject<Aspose::TeX::IO::OutputConsoleTerminal>()); | |
// Default. No need to specify. | |
// Specify memory stream as output terminal, if you don't want terminal output to be written to console. | |
//options.TerminalOut = new OutputMemoryTerminal(); | |
// Set PdfSaveOptions | |
options->set_SaveOptions(System::MakeObject<PdfSaveOptions>()); | |
// Run typesetting. | |
Aspose::TeX::TeX::Typeset(u"hello-world", System::MakeObject<PdfDevice>(), options); | |
// For further output to look write. | |
options->get_TerminalOut()->get_Writer()->WriteLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create typesetting options for default ObjectTeX format on ObjectTeX engine extension. | |
System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::ObjectTeX()); | |
// Specify a file system working directory for input. | |
options->set_InputWorkingDirectory(System::MakeObject<InputFileSystemDirectory>(u"SourceDirectory")); | |
// Specify a file system working directory for output. | |
options->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(u"OutputDirectory")); | |
// Specify console as output terminal. | |
options->set_TerminalOut(System::MakeObject<Aspose::TeX::IO::OutputConsoleTerminal>()); | |
// Default. No need to specify. | |
// Specify memory stream as output terminal, if you don't want terminal output to be written to console. | |
//options.TerminalOut = new OutputMemoryTerminal(); | |
// Run typesetting. | |
Aspose::TeX::TeX::Typeset(u"hello-world", System::MakeObject<XpsDevice>(), options); | |
// For further output to look write. | |
options->get_TerminalOut()->get_Writer()->WriteLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open the source zip file in a stream | |
System::SharedPtr<System::IO::Stream> inZipStream = System::IO::File::Open(System::IO::Path::Combine(u"SourceDirectory", u"zip-in.zip"), System::IO::FileMode::Open); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_1({ inZipStream }); | |
// ------------------------------------------ | |
try { | |
// Open the output zip file in a stream | |
System::SharedPtr<System::IO::Stream> outZipStream = System::IO::File::Open(System::IO::Path::Combine(u"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 input. | |
options->set_InputWorkingDirectory(System::MakeObject<InputZipDirectory>(inZipStream, u"in")); | |
// Specify a ZIP archive working directory for output. | |
options->set_OutputWorkingDirectory(System::MakeObject<OutputZipDirectory>(outZipStream)); | |
// Specify console as 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 consequent output to look write. | |
options->get_TerminalOut()->get_Writer()->WriteLine(); | |
// Finalize 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()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment