-
Notifications
You must be signed in to change notification settings - Fork 57
ES-942103- Add the sample Replace-image-with-new-image #349
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
Open
DharanyaSakthivel-SF4210
wants to merge
1
commit into
main
Choose a base branch
from
ES-942103-Replace-image-with-new-image
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
Paragraphs/Replace-image-with-new-image/.NET/Replace-image-with-new-image.sln
This file contains hidden or 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 16 | ||
VisualStudioVersion = 16.0.31911.196 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-image-with-new-image", "Replace-image-with-new-image\Replace-image-with-new-image.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {EF357FC6-E9E5-4E3C-B932-43F727BE1DE4} | ||
EndGlobalSection | ||
EndGlobal |
Binary file added
BIN
+8.55 KB
...Replace-image-with-new-image/.NET/Replace-image-with-new-image/Data/Picture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+139 KB
Paragraphs/Replace-image-with-new-image/.NET/Replace-image-with-new-image/Data/Template.docx
Binary file not shown.
1 change: 1 addition & 0 deletions
1
Paragraphs/Replace-image-with-new-image/.NET/Replace-image-with-new-image/Output/.gitkeep
This file contains hidden or 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 @@ | ||
|
62 changes: 62 additions & 0 deletions
62
Paragraphs/Replace-image-with-new-image/.NET/Replace-image-with-new-image/Program.cs
This file contains hidden or 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,62 @@ | ||
using Syncfusion.DocIO; | ||
using Syncfusion.DocIO.DLS; | ||
using System.IO; | ||
|
||
namespace Replace_image_with_new_image | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
|
||
// Open the input Word document for reading and writing | ||
using (FileStream inputStream = new FileStream(@"Data/Template.docx", FileMode.Open, FileAccess.ReadWrite)) | ||
{ | ||
WordDocument document = new WordDocument(inputStream, FormatType.Docx); | ||
// Find and process all images in the document | ||
foreach (Entity entity in document.FindAllItemsByProperty(EntityType.Picture, null, null)) | ||
{ | ||
WPicture picture = (WPicture)entity; | ||
float width = picture.Width, height = picture.Height; | ||
// Check if the image is not an SVG | ||
if (picture.SvgData == null) | ||
{ | ||
// Replace the existing image with a new one | ||
using (FileStream imageStream = new FileStream(@"Data/Picture.png", FileMode.Open)) | ||
{ | ||
picture.LoadImage(imageStream); | ||
} | ||
// Preserve the original dimensions | ||
picture.LockAspectRatio = false; | ||
picture.Width = width; | ||
picture.Height = height; | ||
picture.LockAspectRatio = true; | ||
} | ||
else | ||
{ | ||
// Handle SVG conversion to raster image | ||
WParagraph ownerParagraph = picture.OwnerParagraph; | ||
int index = ownerParagraph.ChildEntities.IndexOf(picture); | ||
// Remove the existing SVG image | ||
ownerParagraph.ChildEntities.Remove(picture); | ||
// Create a new image and insert it in the same place | ||
WPicture newPicture = new WPicture(document); | ||
using (FileStream imageStream = new FileStream(@"Data/Picture.png", FileMode.Open)) | ||
{ | ||
newPicture.LoadImage(imageStream); | ||
} | ||
// Set the same dimensions as the original SVG | ||
newPicture.Width = width; | ||
newPicture.Height = height; | ||
ownerParagraph.ChildEntities.Insert(index, newPicture); | ||
} | ||
} | ||
// Save the modified document | ||
using (FileStream outputStream = new FileStream(@"Output/Result.docx", FileMode.Create, FileAccess.Write)) | ||
{ | ||
document.Save(outputStream, FormatType.Docx); | ||
} | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...mage-with-new-image/.NET/Replace-image-with-new-image/Replace-image-with-new-image.csproj
This file contains hidden or 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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>Replace_image_with_new_image</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Data\Picture.png"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Data\Template.docx"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Output\.gitkeep"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.
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.
Does the input document covers both IF, Else cases?
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.
yes sir used png image in header and svg image in table