Skip to content

Commit 9c24b99

Browse files
Replace embedded excel as image feed backs addressed
1 parent 3b6dfd1 commit 9c24b99

File tree

1 file changed

+18
-17
lines changed
  • Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image

1 file changed

+18
-17
lines changed

Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image/Program.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@
55
using Syncfusion.XlsIO;
66
using Syncfusion.XlsIORenderer;
77

8-
//Register Syncfusion license
9-
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Mgo+DSMBMAY9C3t2UlhhQlNHfV5DQmBWfFN0QXNYfVRwdF9GYEwgOX1dQl9nSXZTc0VlWndfcXNSQWc=");
10-
11-
// Initialize the DocIORenderer component for converting Word documents to PDF
12-
using DocIORenderer docIORenderer = new DocIORenderer();
13-
// Open the input Word document from a file stream
14-
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read))
8+
//Initialize the DocIORenderer component for converting Word documents to PDF.
9+
using (DocIORenderer docIORenderer = new DocIORenderer())
1510
{
16-
// Load the Word document into a WordDocument instance
17-
using var tempDocument = new WordDocument(inputStream, FormatType.Automatic);
18-
// Call a method to replace embedded Excel objects in the document with images
19-
ReplaceExcelToImage(tempDocument);
20-
// Convert the Word document to a PDF using the DocIORenderer component
21-
using PdfDocument pdf = docIORenderer.ConvertToPDF(tempDocument);
22-
// Create a file stream to save the output PDF document
23-
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write))
11+
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read))
2412
{
25-
// Save the generated PDF to the specified file stream
26-
pdf.Save(outputStream);
13+
//Open the input Word document.
14+
using (WordDocument document = new WordDocument(inputStream, FormatType.Automatic))
15+
{
16+
//Replace embedded Excel objects in the document with images.
17+
ReplaceExcelToImage(document);
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+
}
2728
}
2829
}
2930

0 commit comments

Comments
 (0)