Skip to content

Commit f6b4450

Browse files
Merge pull request #261 from VijayadharshiniMathiyalagan/ES-871900-How-to-replace-embedded-Excel-with-image
Renamed sample name for Replace embedded excel as Image
2 parents 4f1d745 + aef76e7 commit f6b4450

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.8.34322.80
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-Excel-embedded-image-to-PNG", "Replace-Excel-embedded-image-to-PNG\Replace-Excel-embedded-image-to-PNG.csproj", "{269AC7DF-6678-47E4-BC60-BD9811FAE8C5}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-embedded-excel-as-image", "Replace-embedded-excel-as-image\Replace-embedded-excel-as-image.csproj", "{269AC7DF-6678-47E4-BC60-BD9811FAE8C5}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
using System.Drawing;
2-
using Syncfusion.Pdf;
1+
using Syncfusion.Pdf;
32
using Syncfusion.DocIORenderer;
43
using Syncfusion.DocIO.DLS;
54
using Syncfusion.DocIO;
6-
using Syncfusion.Drawing;
7-
using System.Drawing.Imaging;
85
using Syncfusion.XlsIO;
96
using Syncfusion.XlsIORenderer;
107

11-
// Initialize the DocIORenderer component for converting Word documents to PDF
12-
using DocIORenderer docIORenderer = new DocIORenderer();
13-
// Create new DocIORenderer settings
14-
docIORenderer.Settings = new DocIORendererSettings();
15-
// Open the input Word document from a file stream
16-
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read);
17-
// Load the Word document into a WordDocument instance
18-
using var tempDocument = new WordDocument(inputStream, FormatType.Automatic);
19-
// Call a method to replace embedded Excel objects in the document with images
20-
ReplaceExcelToImage(tempDocument);
21-
// Convert the Word document to a PDF using the DocIORenderer component
22-
using PdfDocument pdf = docIORenderer.ConvertToPDF(tempDocument);
23-
// Create a file stream to save the output PDF document
24-
FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write);
25-
// Save the generated PDF to the specified file stream
26-
pdf.Save(outputStream);
27-
//Dispose the streams.
28-
inputStream.Dispose();
29-
outputStream.Dispose();
8+
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read))
9+
{
10+
//Open the input Word document.
11+
using (WordDocument document = new WordDocument(inputStream, FormatType.Automatic))
12+
{
13+
//Replace embedded Excel objects in the document with images.
14+
ReplaceExcelToImage(document);
15+
//Initialize the DocIORenderer component for converting Word documents to PDF.
16+
using (DocIORenderer docIORenderer = new DocIORenderer())
17+
{
18+
//Convert the Word document to a PDF using the DocIORenderer component.
19+
using (PdfDocument pdf = docIORenderer.ConvertToPDF(document))
20+
{
21+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write))
22+
{
23+
//Save the generated PDF to the specified file stream.
24+
pdf.Save(outputStream);
25+
}
26+
}
27+
}
28+
}
29+
}
3030

3131

3232
/// <summary>
33-
/// Replaces Excel OLE objects in a Word document with images, preserving their original dimensions.
33+
/// Replaces embedded Excel OLE objects in a Word document with their corresponding images while maintaining the original size.
3434
/// </summary>
3535
void ReplaceExcelToImage(WordDocument wordDocument)
3636
{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Syncfusion.DocIORenderer.NET" Version="*" />
13-
<PackageReference Include="Syncfusion.XlsIORenderer.NET" Version="*" />
12+
<PackageReference Include="Syncfusion.DocIORenderer.NET.Core" Version="*" />
13+
<PackageReference Include="Syncfusion.XlsIORenderer.NET.Core" Version="*" />
1414
<PackageReference Include="System.Drawing.Common" Version="8.0.2" />
1515
</ItemGroup>
1616

0 commit comments

Comments
 (0)