Last active
May 11, 2021 15:49
-
-
Save aspose-com-gists/d3eef38ac5b929503e8edee25e0873ce to your computer and use it in GitHub Desktop.
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
Gists for Aspose.TeX for 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
// ExStart:CreateCustomTeXFormatFile | |
// Create typesetting options for no format on ObjectTeX engine extension. | |
System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::get_ObjectIniTeX()); | |
// Specify a file system working directory for input. | |
options->set_InputWorkingDirectory(System::MakeObject<InputFileSystemDirectory>(RunExamples::InputDirectory)); | |
// Specify a file system working directory for output. | |
options->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(RunExamples::OutputDirectory)); | |
// Run format creation. | |
Aspose::TeX::TeX::CreateFormat(u"customtex", options); | |
// For further output to look write. | |
options->get_TerminalOut()->get_Writer()->WriteLine(); | |
// ExEnd:CreateCustomTeXFormatFile |
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
// ExStart:TakeInputFromFileSystem-WriteOutputToFileSystem-WriteTerminalOutputToConsole | |
// 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>(RunExamples::InputDirectory)); | |
// Specify a file system working directory for output. | |
options->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(RunExamples::OutputDirectory)); | |
// Specify console as output terminal. | |
options->set_TerminalOut(System::MakeObject<OutputConsoleTerminal>()); | |
// Default. No need to specify. | |
// Specify memory stream as output terminal, if you don't 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(); | |
// The same as Console.Out.WriteLine(); | |
// ExEnd:TakeInputFromFileSystem-WriteOutputToFileSystem-WriteTerminalOutputToConsole |
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
// ExStart:LoadLicenseFromFile | |
// Initialize license object | |
System::SharedPtr<License> license = System::MakeObject<License>(); | |
// Set license | |
license->SetLicense(u"D:\\Aspose.Total.NET.lic"); | |
System::Console::WriteLine(u"License set successfully."); | |
// ExEnd:LoadLicenseFromFile |
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
// ExStart:LoadLicenseFromStream | |
// Initialize license object | |
System::SharedPtr<License> license = System::MakeObject<License>(); | |
// Load license in FileStream | |
System::SharedPtr<System::IO::FileStream> myStream = System::MakeObject<System::IO::FileStream>(u"D:\\Aspose.Total.NET.lic", System::IO::FileMode::Open); | |
// Set license | |
license->SetLicense(myStream); | |
System::Console::WriteLine(u"License set successfully."); | |
// ExEnd:LoadLicenseFromStream |
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
// ExStart:OverrideJobName-WriteTerminalOutputToFileSystem | |
// Create typesetting options for default ObjectTeX format on ObjectTeX engine extension. | |
System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::ObjectTeX()); | |
// Specify the job name. Otherwise, TeX.Typeset()'s method first argument will be taken as a job name. | |
options->set_JobName(u"overriden-job-name"); | |
// Specify a file system working directory for input. | |
options->set_InputWorkingDirectory(System::MakeObject<InputFileSystemDirectory>(RunExamples::InputDirectory)); | |
// Specify a file system working directory for output. | |
options->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(RunExamples::OutputDirectory)); | |
// Specify that the terminal output must be written to a file in the output working directory. | |
// The file name is <job_name>.trm. | |
options->set_TerminalOut(System::MakeObject<OutputFileTerminal>(options->get_OutputWorkingDirectory())); | |
// Run typesetting. | |
Aspose::TeX::TeX::Typeset(u"hello-world", System::MakeObject<XpsDevice>(), options); | |
// ExEnd:OverrideJobName-WriteTerminalOutputToFileSystem |
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
// ExStart:WriteTerminalOutputToZip | |
// 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"terminal-out-to-zip.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 the job name. | |
options->set_JobName(u"terminal-output-to-zip"); | |
// 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 that the terminal output must be written to a file in the output working directory. | |
// The file name is <job_name>.trm. | |
options->set_TerminalOut(System::MakeObject<OutputFileTerminal>(options->get_OutputWorkingDirectory())); | |
// Create and specify saving options. | |
options->set_SaveOptions(System::MakeObject<PdfSaveOptions>()); | |
// Run typesetting. | |
Aspose::TeX::TeX::Typeset(u"hello-world", System::MakeObject<PdfDevice>(), options); | |
// 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()); | |
} | |
} | |
// ExEnd:WriteTerminalOutputToZip |
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
// ExStart:TakeMainInputFromStream-AuxFromFileSystem-TakeTerminalInputFromConsole-AlternativeImagesStorage | |
// Create typesetting options for default ObjectTeX format on ObjectTeX engine extension. | |
System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::ObjectTeX()); | |
// Specify the job name. | |
options->set_JobName(u"stream-in-image-out"); | |
// Specify a file system working directory for input. | |
options->set_InputWorkingDirectory(System::MakeObject<InputFileSystemDirectory>(RunExamples::InputDirectory)); | |
// Specify a file system working directory for output. | |
options->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(RunExamples::OutputDirectory)); | |
// Specify console as input terminal. | |
options->set_TerminalIn(System::MakeObject<InputConsoleTerminal>()); | |
// Default. No need to specify. | |
// Specify console as output terminal. | |
options->set_TerminalOut(System::MakeObject<OutputConsoleTerminal>()); | |
// Default. No need to specify. | |
// Create and specify saving options. | |
options->set_SaveOptions([&]{ auto tmp_0 = System::MakeObject<PngSaveOptions>(); tmp_0->set_Resolution(300); return tmp_0; }()); | |
// Create image device. | |
System::SharedPtr<ImageDevice> device = System::MakeObject<ImageDevice>(); | |
// Run typesetting. | |
Aspose::TeX::TeX::Typeset(System::MakeObject<System::IO::MemoryStream>(System::Text::Encoding::get_ASCII()->GetBytes(u"\\hrule height 10pt width 95pt\\vskip10pt\\hrule height 5pt")), device, options); | |
// When console prompts the input, type "ABC", press Enter, then type "\end" and press Enter again. | |
// For further output to look write. | |
options->get_TerminalOut()->get_Writer()->WriteLine(); | |
// You can alternatively get images in form of array of byte arrays. | |
// The first index for the page number (0-based, of course). | |
System::ArrayPtr<System::ArrayPtr<uint8_t>> result = device->get_Result(); | |
// ExEnd:TakeMainInputFromStream-AuxFromFileSystem-TakeTerminalInputFromConsole-AlternativeImagesStorage |
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
// ExStart:WriteOutputPdfToExternalStream | |
// 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_2({ inZipStream}); | |
// ------------------------------------------ | |
try{ | |
System::SharedPtr<System::IO::Stream> outZipStream = System::IO::File::Open(System::IO::Path::Combine(RunExamples::OutputDirectory, u"typeset-pdf-to-external-stream.zip"), System::IO::FileMode::Create); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_1({ outZipStream}); | |
// ------------------------------------------ | |
try | |
{ | |
// Create typesetting options for default ObjectTeX format on ObjectTeX engine extension. | |
System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::ObjectTeX()); | |
// Specify the job name. | |
options->set_JobName(u"typeset-pdf-to-external-stream"); | |
// does NOT define the name of the output PDF. | |
// 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 that the terminal output must be written to a file in the output working directory. | |
// The file name is <job_name>.trm. | |
options->set_TerminalOut(System::MakeObject<OutputFileTerminal>(options->get_OutputWorkingDirectory())); | |
// Create and specify saving options. | |
options->set_SaveOptions(System::MakeObject<PdfSaveOptions>()); | |
// Open a stream to write the output PDF to. | |
// 1) A file somewhere on a local file system. | |
{ | |
System::SharedPtr<System::IO::Stream> stream = System::IO::File::Open(System::IO::Path::Combine(RunExamples::OutputDirectory, u"file-name.pdf"), System::IO::FileMode::Create); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ stream}); | |
// ------------------------------------------ | |
try | |
{ | |
Aspose::TeX::TeX::Typeset(u"hello-world", System::MakeObject<PdfDevice>(stream), options); | |
} | |
catch(...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
// Finalize output ZIP archive. | |
(System::DynamicCast<Aspose::TeX::IO::OutputZipDirectory>(options->get_OutputWorkingDirectory()))->Finish(); | |
} | |
catch(...) | |
{ | |
__dispose_guard_1.SetCurrentException(std::current_exception()); | |
} | |
} | |
catch(...) | |
{ | |
__dispose_guard_2.SetCurrentException(std::current_exception()); | |
} | |
} | |
// ExEnd:WriteOutputPdfToExternalStream |
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
// ExStart:TypesetWithCustomTeXFormat | |
// Create a file system input working directory. | |
System::SharedPtr<IWorkingDirectory> wd = System::MakeObject<InputFileSystemDirectory>(RunExamples::OutputDirectory); | |
// Create a format provider. | |
{ | |
System::SharedPtr<FormatProvider> formatProvider = System::MakeObject<FormatProvider>(wd, u"customtex"); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ formatProvider}); | |
// ------------------------------------------ | |
try | |
{ | |
// Create typesetting options for a custom format on ObjectTeX engine extension. | |
System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::ObjectTeX(formatProvider)); | |
options->set_JobName(u"typeset-with-custom-format"); | |
// Specify the input working directory. | |
options->set_InputWorkingDirectory(wd); | |
// Specify a file system working directory for output. | |
options->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(RunExamples::OutputDirectory)); | |
// Run typesetting. | |
Aspose::TeX::TeX::Typeset(System::MakeObject<System::IO::MemoryStream>(System::Text::Encoding::get_ASCII()->GetBytes(u"Congratulations! You have successfully typeset this text with your own TeX format!\\end")), System::MakeObject<XpsDevice>(), options); | |
// For further output to look write. | |
options->get_TerminalOut()->get_Writer()->WriteLine(); | |
} | |
catch(...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
// ExEnd:TypesetWithCustomTeXFormat |
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
// ExStart:WriteOutputXpsToExternalStream | |
// Create typesetting options for default ObjectTeX format on ObjectTeX engine extension. | |
System::SharedPtr<TeXOptions> options = TeXOptions::ConsoleAppOptions(TeXConfig::ObjectTeX()); | |
// Specify a job name. | |
options->set_JobName(u"external-file-stream"); | |
// Specify a file system working directory for input. | |
options->set_InputWorkingDirectory(System::MakeObject<InputFileSystemDirectory>(RunExamples::InputDirectory)); | |
// Specify a file system working directory for output. | |
options->set_OutputWorkingDirectory(System::MakeObject<OutputFileSystemDirectory>(RunExamples::OutputDirectory)); | |
// Specify that the terminal output must be written to a file in the output working directory. | |
// The file name is <job_name>.trm. | |
options->set_TerminalOut(System::MakeObject<OutputFileTerminal>(options->get_OutputWorkingDirectory())); | |
// Open a stream to write typeset XPS document. File name not necessarily the same as the job name. | |
{ | |
System::SharedPtr<System::IO::Stream> stream = System::IO::File::Open(System::IO::Path::Combine(RunExamples::OutputDirectory, options->get_JobName() + u".xps"), System::IO::FileMode::Create); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ stream}); | |
// ------------------------------------------ | |
try | |
{ | |
Aspose::TeX::TeX::Typeset(u"hello-world", System::MakeObject<XpsDevice>(stream), options); | |
} | |
catch(...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
// ExEnd:WriteOutputXpsToExternalStream |
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
// ExStart:TakeInputFromZip-WriteOutputToZip | |
// 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 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()); | |
} | |
} | |
// ExEnd:TakeInputFromZip-WriteOutputToZip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment