-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sample for convert web page to word document #271
Open
VijayadharshiniMathiyalagan
wants to merge
1
commit into
SyncfusionExamples:main
Choose a base branch
from
VijayadharshiniMathiyalagan:ES-875349-How-to-convert-Webpage-to-Word-document
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
HTML-conversions/Convert-Webpage-to-Word-document/Convert-Webpage-to-Word-document.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.12.35309.182 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Convert-Webpage-to-Word-document", "Convert-Webpage-to-Word-document\Convert-Webpage-to-Word-document.csproj", "{2C603F46-8AE1-4CB2-A51E-2E7E17F0D6E0}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{2C603F46-8AE1-4CB2-A51E-2E7E17F0D6E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2C603F46-8AE1-4CB2-A51E-2E7E17F0D6E0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2C603F46-8AE1-4CB2-A51E-2E7E17F0D6E0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2C603F46-8AE1-4CB2-A51E-2E7E17F0D6E0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {CC794805-DD23-4D06-8219-488DFE30DAB9} | ||
EndGlobalSection | ||
EndGlobal |
21 changes: 21 additions & 0 deletions
21
...to-Word-document/Convert-Webpage-to-Word-document/Convert-Webpage-to-Word-document.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>Convert_Webpage_to_Word_document</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Output\.gitkeep"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
1 change: 1 addition & 0 deletions
1
...ersions/Convert-Webpage-to-Word-document/Convert-Webpage-to-Word-document/Output/.gitkeep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
60 changes: 60 additions & 0 deletions
60
...-conversions/Convert-Webpage-to-Word-document/Convert-Webpage-to-Word-document/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Net; | ||
using Syncfusion.DocIO; | ||
using Syncfusion.DocIO.DLS; | ||
|
||
//Register Syncfusion license | ||
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Mgo+DSMBMAY9C3t2UlhhQlNHfV5DQmBWfFN0QXNYfVRwdF9GYEwgOX1dQl9nSXZTc0VlWndfcXNSQWc="); | ||
|
||
// Request URLs for header, footer, and main body content. | ||
Console.WriteLine("Please enter the URL for the header content:"); | ||
string headerHtmlUrl = Console.ReadLine(); | ||
Console.WriteLine("Please enter the URL for the footer content:"); | ||
string footerHtmlUrl = Console.ReadLine(); | ||
Console.WriteLine("Please enter the URL for the main body content:"); | ||
string bodyHtmlUrl = Console.ReadLine(); | ||
// Retrieve HTML content from the specified URLs. | ||
string headerContent = GetHtmlContent(headerHtmlUrl); | ||
string footerContent = GetHtmlContent(footerHtmlUrl); | ||
string mainContent = GetHtmlContent(bodyHtmlUrl); | ||
// Create a new Word document instance. | ||
using (WordDocument document = new WordDocument()) | ||
{ | ||
// Add a new section to the document. | ||
WSection section = document.AddSection() as WSection; | ||
// Append the main content HTML to the paragraph. | ||
WParagraph paragraph = section.AddParagraph() as WParagraph; | ||
paragraph.AppendHTML(mainContent); | ||
// Append the header content HTML to the header paragraph. | ||
paragraph = section.HeadersFooters.OddHeader.AddParagraph() as WParagraph; | ||
paragraph.AppendHTML(headerContent); | ||
// Append the footer content HTML to the footer paragraph. | ||
paragraph = section.HeadersFooters.OddFooter.AddParagraph() as WParagraph; | ||
paragraph.AppendHTML(footerContent); | ||
// Save the modified document. | ||
using (FileStream outputStream = new FileStream("Output/Output.docx", FileMode.Create, FileAccess.Write)) | ||
{ | ||
document.Save(outputStream, FormatType.Docx); // Save the document in DOCX format. | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Fetches the HTML content from a given URL by sending a GET request and reading the server's response stream. | ||
/// </summary> | ||
string GetHtmlContent(string url) | ||
{ | ||
// Create a web request to the specified URL. | ||
WebRequest myRequest = WebRequest.Create(url); | ||
// Set the request method to GET to fetch data from the URL. | ||
myRequest.Method = "GET"; | ||
// Get the response from the web server. | ||
WebResponse myResponse = myRequest.GetResponse(); | ||
// Read the response stream and return the HTML content as a string. | ||
using (StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8)) | ||
{ | ||
// Read all content from the response stream. | ||
string result = sr.ReadToEnd(); | ||
// Return the HTML content as a string. | ||
return result; | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove license key in samples