Skip to content

Commit 0b1f0d2

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

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
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-PDF", "LaTeX-equation-into-PDF\LaTeX-equation-into-PDF.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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIORenderer;
3+
using Syncfusion.Pdf;
4+
5+
// Create a new Word document.
6+
using (WordDocument document = new WordDocument())
7+
{
8+
//Add one section and one paragraph to the document.
9+
document.EnsureMinimal();
10+
11+
//Append an accent equation using LaTeX.
12+
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)}");
13+
14+
//Instantiation of DocIORenderer for Word to PDF conversion
15+
DocIORenderer render = new DocIORenderer();
16+
//render.Settings.AutoDetectComplexScript = true;
17+
//Converts Word document into PDF document
18+
PdfDocument pdfDocument = render.ConvertToPDF(document);
19+
//Releases all resources used by the Word document and DocIO Renderer objects
20+
render.Dispose();
21+
document.Dispose();
22+
//Save the Word document.
23+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../Result.pdf"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
24+
{
25+
pdfDocument.Save(outputStream);
26+
}
27+
//Close the Word document
28+
document.Close();
29+
//Closes the instance of PDF document object
30+
pdfDocument.Close();
31+
}

0 commit comments

Comments
 (0)