Skip to content

Commit d63f55c

Browse files
1006383-Modified the sample
1 parent 2ce4d23 commit d63f55c

5 files changed

Lines changed: 63 additions & 50 deletions

File tree

  • Performance-metrices
    • Fallback-Font-Image/.NET/Fallback-Font/Fallback-Font
    • Font-Substitution-Image/.NET/Font-Substitution/Font-Substitution
    • Use-embedded-Word-fonts-image/.NET/Use-embedded-Word-fonts/Use-embedded-Word-fonts
    • Use-embeded-word-font-PDF/.NET/Use-embeded-word-font/Use-embeded-word-font
    • Word-to-Image/.NET/Word-document-to-image/Word-document-to-image

Performance-metrices/Fallback-Font-Image/.NET/Fallback-Font/Fallback-Font/Program.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@ static void Main()
1313
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
1414
{
1515
// Open an existing Word document
16-
WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx);
17-
//Initialize the default fallback fonts collection.
18-
document.FontSettings.FallbackFonts.InitializeDefault();
19-
DocIORenderer renderer = new DocIORenderer();
20-
//Convert the entire Word document to images.
21-
Stream[] imageStreams = document.RenderAsImages();
22-
for (int i = 0; i < imageStreams.Length; i++)
16+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
2317
{
24-
//Save the image stream as file.
25-
string imagePath = Path.Combine(Path.GetFullPath(@"Output/Images"), $"WordToImage_{i + 1}.jpg");
26-
using (FileStream fileStreamOutput = new(imagePath, FileMode.Create, FileAccess.Write))
18+
//Initialize the default fallback fonts collection.
19+
document.FontSettings.FallbackFonts.InitializeDefault();
20+
using (DocIORenderer renderer = new DocIORenderer())
2721
{
28-
imageStreams[i].CopyTo(fileStreamOutput);
22+
//Convert the entire Word document to images.
23+
Stream[] imageStreams = document.RenderAsImages();
24+
for (int i = 0; i < imageStreams.Length; i++)
25+
{
26+
//Save the image stream as file.
27+
string imagePath = Path.Combine(Path.GetFullPath(@"Output/Images"), $"WordToImage_{i + 1}.jpg");
28+
using (FileStream fileStreamOutput = new(imagePath, FileMode.Create, FileAccess.Write))
29+
{
30+
imageStreams[i].CopyTo(fileStreamOutput);
31+
}
32+
}
2933
}
3034
}
3135
stopwatch.Stop();

Performance-metrices/Font-Substitution-Image/.NET/Font-Substitution/Font-Substitution/Program.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,27 @@ static void Main()
1313
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
1414
{
1515
// Open an existing Word document
16-
WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx);
17-
//Hooks the font substitution event
18-
document.FontSettings.SubstituteFont += FontSettings_SubstituteFont;
19-
DocIORenderer renderer = new DocIORenderer();
20-
//Convert the entire Word document to images.
21-
Stream[] imageStreams = document.RenderAsImages();
22-
//Unhooks the font substitution event after converting to PDF
23-
document.FontSettings.SubstituteFont -= FontSettings_SubstituteFont;
24-
for (int i = 0; i < imageStreams.Length; i++)
16+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
2517
{
26-
//Save the image stream as file.
27-
string imagePath = Path.Combine(Path.GetFullPath(@"Output/Images"), $"WordToImage_{i + 1}.jpg");
28-
using (FileStream fileStreamOutput = new(imagePath, FileMode.Create, FileAccess.Write))
18+
//Hooks the font substitution event
19+
document.FontSettings.SubstituteFont += FontSettings_SubstituteFont;
20+
using (DocIORenderer renderer = new DocIORenderer())
2921
{
30-
imageStreams[i].CopyTo(fileStreamOutput);
31-
}
32-
}
22+
//Convert the entire Word document to images.
23+
Stream[] imageStreams = document.RenderAsImages();
24+
//Unhooks the font substitution event after converting to PDF
25+
document.FontSettings.SubstituteFont -= FontSettings_SubstituteFont;
26+
for (int i = 0; i < imageStreams.Length; i++)
27+
{
28+
//Save the image stream as file.
29+
string imagePath = Path.Combine(Path.GetFullPath(@"Output/Images"), $"WordToImage_{i + 1}.jpg");
30+
using (FileStream fileStreamOutput = new(imagePath, FileMode.Create, FileAccess.Write))
31+
{
32+
imageStreams[i].CopyTo(fileStreamOutput);
33+
}
34+
}
35+
}
36+
}
3337
stopwatch.Stop();
3438
Console.WriteLine($"Word To Image processed in {stopwatch.Elapsed.TotalSeconds} seconds");
3539
}

Performance-metrices/Use-embedded-Word-fonts-image/.NET/Use-embedded-Word-fonts/Use-embedded-Word-fonts/Program.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ static void Main()
1414
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
1515
{
1616
// Open an existing Word document
17-
WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx);
18-
DocIORenderer renderer = new DocIORenderer();
19-
//Sets true to embed fonts True
20-
renderer.Settings.EmbedFonts = true;
21-
//Convert the entire Word document to images.
22-
Stream[] imageStreams = document.RenderAsImages();
23-
for (int i = 0; i < imageStreams.Length; i++)
17+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
2418
{
25-
//Save the image stream as file.
26-
string imagePath = Path.Combine(Path.GetFullPath(@"Output/Images"), $"WordToImage_{i + 1}.jpg");
27-
using (FileStream fileStreamOutput = new(imagePath, FileMode.Create, FileAccess.Write))
19+
using (DocIORenderer renderer = new DocIORenderer())
2820
{
29-
imageStreams[i].CopyTo(fileStreamOutput);
21+
//Convert the entire Word document to images.
22+
Stream[] imageStreams = document.RenderAsImages();
23+
for (int i = 0; i < imageStreams.Length; i++)
24+
{
25+
//Save the image stream as file.
26+
string imagePath = Path.Combine(Path.GetFullPath(@"Output/Images"), $"WordToImage_{i + 1}.jpg");
27+
using (FileStream fileStreamOutput = new(imagePath, FileMode.Create, FileAccess.Write))
28+
{
29+
imageStreams[i].CopyTo(fileStreamOutput);
30+
}
31+
}
3032
}
3133
}
3234
stopwatch.Stop();

Performance-metrices/Use-embeded-word-font-PDF/.NET/Use-embeded-word-font/Use-embeded-word-font/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ static void Main()
1919
//Creates an instance of DocIORenderer.
2020
using (DocIORenderer renderer = new DocIORenderer())
2121
{
22-
//Sets true to embed fonts True
23-
renderer.Settings.EmbedFonts = true;
2422
//Converts Word document into PDF document.
2523
using (PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument))
2624
{

Performance-metrices/Word-to-Image/.NET/Word-document-to-image/Word-document-to-image/Program.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Syncfusion.DocIO.DLS;
33
using Syncfusion.DocIORenderer;
44
using System.Diagnostics;
5+
using System.Reflection.Metadata;
56

67
class Program
78
{
@@ -13,22 +14,26 @@ static void Main()
1314
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
1415
{
1516
// Open an existing Word document
16-
WordDocument document = new WordDocument(fileStreamPath,FormatType.Docx);
17-
DocIORenderer renderer = new DocIORenderer();
18-
//Convert the entire Word document to images.
19-
Stream[] imageStreams = document.RenderAsImages();
20-
for (int i = 0; i < imageStreams.Length; i++)
17+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
2118
{
22-
//Save the image stream as file.
23-
string imagePath = Path.Combine(Path.GetFullPath(@"Output/Images"), $"WordToImage_{i + 1}.jpg");
24-
using (FileStream fileStreamOutput = new(imagePath, FileMode.Create, FileAccess.Write))
19+
using (DocIORenderer renderer = new DocIORenderer())
2520
{
26-
imageStreams[i].CopyTo(fileStreamOutput);
27-
}
21+
//Convert the entire Word document to images.
22+
Stream[] imageStreams = document.RenderAsImages();
23+
for (int i = 0; i < imageStreams.Length; i++)
24+
{
25+
//Save the image stream as file.
26+
string imagePath = Path.Combine(Path.GetFullPath(@"Output/Images"), $"WordToImage_{i + 1}.jpg");
27+
using (FileStream fileStreamOutput = new(imagePath, FileMode.Create, FileAccess.Write))
28+
{
29+
imageStreams[i].CopyTo(fileStreamOutput);
30+
}
31+
}
32+
}
2833
}
2934
stopwatch.Stop();
3035
Console.WriteLine($"Word To Image processed in {stopwatch.Elapsed.TotalSeconds} seconds");
31-
}
36+
}
3237
}
3338
catch (Exception ex)
3439
{

0 commit comments

Comments
 (0)