|
1 | | -using System.Drawing; |
2 | | -using Syncfusion.Pdf; |
| 1 | +using Syncfusion.Pdf; |
3 | 2 | using Syncfusion.DocIORenderer; |
4 | 3 | using Syncfusion.DocIO.DLS; |
5 | 4 | using Syncfusion.DocIO; |
6 | | -using Syncfusion.Drawing; |
7 | | -using System.Drawing.Imaging; |
8 | 5 | using Syncfusion.XlsIO; |
9 | 6 | using Syncfusion.XlsIORenderer; |
10 | 7 |
|
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 | +} |
30 | 30 |
|
31 | 31 |
|
32 | 32 | /// <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. |
34 | 34 | /// </summary> |
35 | 35 | void ReplaceExcelToImage(WordDocument wordDocument) |
36 | 36 | { |
|
0 commit comments