Skip to content

Commit eaacda9

Browse files
author
sneha.biju
committed
Sample to create equation using LaTeX and convert it to Image
1 parent 0b1f0d2 commit eaacda9

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34322.80
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaTeX-equation-into-Image", "LaTeX-equation-into-Image\LaTeX-equation-into-Image.csproj", "{2198BE02-2850-468C-8C30-C8386D8324B4}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{2198BE02-2850-468C-8C30-C8386D8324B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{2198BE02-2850-468C-8C30-C8386D8324B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{2198BE02-2850-468C-8C30-C8386D8324B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{2198BE02-2850-468C-8C30-C8386D8324B4}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {27F0B50D-0D1B-4928-BA46-EDEDCB1CA1B4}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<RootNamespace>LaTeX_equation_into_PDF</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using Syncfusion.DocIORenderer;
4+
using Syncfusion.Pdf;
5+
6+
// Create a new Word document.
7+
using (WordDocument document = new WordDocument())
8+
{
9+
//Add one section and one paragraph to the document.
10+
document.EnsureMinimal();
11+
12+
//Append an accent equation using LaTeX.
13+
document.LastParagraph.AppendMath(@"f\left(x\right)={a}_{0}+\sum_{n=1}^{\infty}{\left({a}_{n}\cos{\frac{n\pi{x}}{L}}+{b}_{n}\sin{\frac{n\pi{x}}{L}}\right)}");
14+
15+
//Instantiation of DocIORenderer for Word to PDF conversion
16+
DocIORenderer render = new DocIORenderer();
17+
//Convert the first page of the Word document into an image.
18+
Stream imageStream = document.RenderAsImages(0, ExportImageFormat.Jpeg);
19+
//Reset the stream position.
20+
imageStream.Position = 0;
21+
//Save the stream as file.
22+
using (FileStream fileStreamOutput = File.Create("../../../Result.jpeg"))
23+
{
24+
imageStream.CopyTo(fileStreamOutput);
25+
}
26+
//Close the Word document
27+
document.Close();
28+
}

Mathematical-Equation/LaTeX-equations/LaTeX-equation-into-PDF/.NET Standard/LaTeX-equation-into-PDF/Program.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
//Instantiation of DocIORenderer for Word to PDF conversion
1515
DocIORenderer render = new DocIORenderer();
16-
//render.Settings.AutoDetectComplexScript = true;
1716
//Converts Word document into PDF document
1817
PdfDocument pdfDocument = render.ConvertToPDF(document);
1918
//Releases all resources used by the Word document and DocIO Renderer objects
@@ -24,8 +23,6 @@
2423
{
2524
pdfDocument.Save(outputStream);
2625
}
27-
//Close the Word document
28-
document.Close();
2926
//Closes the instance of PDF document object
3027
pdfDocument.Close();
3128
}

0 commit comments

Comments
 (0)