Last active
          August 26, 2021 11:23 
        
      - 
      
- 
        Save aspose-com-kb/b565320de9754ee50aaa6344efd7c4fb to your computer and use it in GitHub Desktop. 
    Render LaTeX (TeX) File to PNG Image Format. The explanation of this code can be found in this topic: https://kb.aspose.com/tex/net/how-to-render-latex-to-png-in-c-sharp/.
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | using System; | |
| using System.IO; | |
| //Add reference to Aspose.TeX for .NET API | |
| //Use following namespaces to render Latex file to PNG format | |
| using Aspose.TeX; | |
| using Aspose.TeX.IO; | |
| using Aspose.TeX.Presentation.Image; | |
| namespace RenderLatexToPNG | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| //Set Aspose license before rendering latex file to PNG format | |
| Aspose.TeX.License AsposeTeXLicense = new Aspose.TeX.License(); | |
| AsposeTeXLicense.SetLicense(@"c:\asposelicense\license.lic"); | |
| //Create TeXOptions object with ObjectTex config settings | |
| TeXOptions TeXFormatOptions = TeXOptions.ConsoleAppOptions(TeXConfig.ObjectTeX()); | |
| //Set input and output working directory | |
| TeXFormatOptions.InputWorkingDirectory = new InputFileSystemDirectory(@"c:\samples"); | |
| TeXFormatOptions.OutputWorkingDirectory = new OutputFileSystemDirectory(@"c:\samples"); | |
| //Set output terminal option to file terminal to save to a file | |
| TeXFormatOptions.TerminalOut = new OutputFileTerminal(TeXFormatOptions.OutputWorkingDirectory); | |
| //PNG save options | |
| PngSaveOptions pngSaveOptions = new PngSaveOptions(); | |
| pngSaveOptions.Resolution = 300; | |
| TeXFormatOptions.SaveOptions = pngSaveOptions; | |
| //Create an ImageDevice object | |
| ImageDevice imageDevice = new ImageDevice(); | |
| //Run typesetting. | |
| TeX.Typeset("customtex", imageDevice, TeXFormatOptions); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment