|
5 | 5 | using Syncfusion.XlsIO; |
6 | 6 | using Syncfusion.XlsIORenderer; |
7 | 7 |
|
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()) |
15 | 10 | { |
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)) |
24 | 12 | { |
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 | + } |
27 | 28 | } |
28 | 29 | } |
29 | 30 |
|
|
0 commit comments