Latest source merged from Syncfusion
This commit is contained in:
Родитель
725bfabd56
Коммит
6162ebc78e
|
@ -127,6 +127,85 @@ wordDocument.Close()
|
|||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
||||
|
||||
The following code snippet illustrates how to convert a Word document to an image using custom image resolution.
|
||||
|
||||
|
||||
{% tabs %}
|
||||
{% highlight c# %}
|
||||
//Load an existing Word document.
|
||||
using (WordDocument wordDocument = new WordDocument(@"Template.docx", FormatType.Docx))
|
||||
{
|
||||
//Initialize the ChartToImageConverter for converting charts during Word to image conversion.
|
||||
wordDocument.ChartToImageConverter = new ChartToImageConverter();
|
||||
//Set the scaling mode for charts (Normal mode reduces the file size).
|
||||
wordDocument.ChartToImageConverter.ScalingMode = ScalingMode.Normal;
|
||||
//Convert the word document to images.
|
||||
Image[] images = wordDocument.RenderAsImages(ImageType.Metafile);
|
||||
//Declare the variables to hold custom width and height.
|
||||
int customWidth = 1500;
|
||||
int customHeight = 1500;
|
||||
foreach (Image image in images)
|
||||
{
|
||||
MemoryStream stream = new MemoryStream();
|
||||
image.Save(stream, ImageFormat.Png);
|
||||
//Create a bitmap of specific width and height.
|
||||
Bitmap bitmap = new Bitmap(customWidth, customHeight, PixelFormat.Format32bppPArgb);
|
||||
//Get the graphics from an image.
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
//Set the resolution.
|
||||
bitmap.SetResolution(300, 300);
|
||||
//Recreate the image in custom size.
|
||||
graphics.DrawImage(System.Drawing.Image.FromStream(stream), new Rectangle(0, 0, bitmap.Width, bitmap.Height));
|
||||
//Save the image as a bitmap.
|
||||
bitmap.Save(@"ImageOutput" + Guid.NewGuid().ToString() + ".png");
|
||||
}
|
||||
}
|
||||
{% endhighlight %}
|
||||
|
||||
{% highlight vb.net %}
|
||||
'Load an existing Word document.
|
||||
Using wordDocument As WordDocument = New WordDocument("Template.docx", FormatType.Docx)
|
||||
'Initialize the ChartToImageConverter for converting charts during Word to image conversion.
|
||||
wordDocument.ChartToImageConverter = New ChartToImageConverter()
|
||||
'Set the scaling mode for charts (Normal mode reduces the file size).
|
||||
wordDocument.ChartToImageConverter.ScalingMode = ScalingMode.Normal
|
||||
'Convert the word document to images.
|
||||
Dim images() As Image = wordDocument.RenderAsImages(ImageType.Metafile)
|
||||
'Declare the variables to hold custom width and height.
|
||||
Dim customWidth As Integer = 1500
|
||||
Dim customHeight As Integer = 1500
|
||||
For Each image As Image In images
|
||||
Dim stream As MemoryStream = New MemoryStream
|
||||
image.Save(stream, ImageFormat.Png)
|
||||
'Create a bitmap of specific width and height.
|
||||
Dim bitmap As Bitmap = New Bitmap(customWidth, customHeight, PixelFormat.Format32bppPArgb)
|
||||
'Get the graphics from an image.
|
||||
Dim graphics As Graphics = Graphics.FromImage(bitmap)
|
||||
'Set the resolution.
|
||||
bitmap.SetResolution(300, 300)
|
||||
'Recreate the image in custom size.
|
||||
graphics.DrawImage(System.Drawing.Image.FromStream(stream), New Rectangle(0, 0, bitmap.Width, bitmap.Height))
|
||||
'Save the image as a bitmap.
|
||||
bitmap.Save(("ImageOutput" + (Guid.NewGuid.ToString + ".png")))
|
||||
Next
|
||||
|
||||
End Using
|
||||
{% endhighlight %}
|
||||
|
||||
{% highlight UWP %}
|
||||
//DocIO only supports Word to image conversion in Windows Forms, WPF, ASP.NET and ASP.NET MVC platform.
|
||||
{% endhighlight %}
|
||||
|
||||
{% highlight ASP.NET CORE %}
|
||||
//DocIO only supports Word to image conversion in Windows Forms, WPF, ASP.NET and ASP.NET MVC platform.
|
||||
{% endhighlight %}
|
||||
|
||||
{% highlight XAMARIN %}
|
||||
//DocIO only supports Word to image conversion in Windows Forms, WPF, ASP.NET and ASP.NET MVC platform.
|
||||
{% endhighlight %}
|
||||
{% endtabs %}
|
||||
|
||||
N> 1. Word to Image conversion is not supported in Silverlight, Windows Phone, WinRT, Universal, Xamarin, ASP.NET Core, Blazor and Universal Windows Platform applications.
|
||||
N> 2. In Azure Web Service and Azure APP Service, .NET GDI+ (System.Drawing) does not support the Metafile image (vector image). So, the image will be generated as Bitmap (raster image).
|
||||
N> 3. Creating an instance of the ChartToImageConverter class is mandatory to convert the charts present in the Word document to Image. Otherwise, the charts are not preserved in the generated image.
|
||||
|
|
Загрузка…
Ссылка в новой задаче