We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Shapes with ODT and html

Hello, I am creating an elipse using the shape object:

Aspose.Words.Drawing.Shape elipse = new Aspose.Words.Drawing.Shape(builder.Document, Aspose.Words.Drawing.ShapeType.Ellipse);

elipse.FillColor = Color.Red;
elipse.Width = 10;
elipse.Height = 10;
builder.InsertNode(elipse);

When i save the document as ODT, HTML or MHTML the shapes are lost. (PDF and all Word formats works fine).
I guess html and odt does not support vector graphics. Maybe if the shapes were converted to Emf images internally it would work.

My current solution is to render an EMF Image using the .NET graphics object and inserting it to the document:

using (MemoryStream stream = new MemoryStream())
using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
using (System.Drawing.Graphics gTmp = System.Drawing.Graphics.FromImage(bmp))
{
System.IntPtr hdc = gTmp.GetHdc();
using (System.Drawing.Imaging.Metafile metafile = new System.Drawing.Imaging.Metafile(stream, hdc, new System.Drawing.Rectangle(0, 0, 10, 10), System.Drawing.Imaging.MetafileFrameUnit.Pixel, System.Drawing.Imaging.EmfType.EmfPlusDual))
using (Graphics g = Graphics.FromImage(metafile))
{
g.FillEllipse(Brushes.Red, 0, 0, 10, 10);
gTmp.ReleaseHdc(hdc);
}
builder.InsertImage(stream);
}

Using this solution, if I save as PDF will the image be treated as vector graphics or converted to a Bitmap?

I am using Aspose 6.0

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Only Images and horizontal rules are exported to HTML (MHTML). This is known issue #1146.

Issue #1146 – Render shapes as image files when exporting to HTML

Regarding ODT. Note ODT format is currently in beta and not all features are supported. Anyway I created new issue #6906 in our defect database.

Regarding PDF. If you use direct conversion to PDF (Without Aspose.Pdf) EMF image will be treated as vector graphics.

If you are using old method of DOC to PDF conversion (Using Aspose.Pdf) EMF image will be treated as raster images.

Best regards.

Thanks for the quick response.
I'am using the built in PDF rendering engine.
I am however getting some strange results when using a LinearGradientBrush instead of a SoldBrush to fill the elipse when I save as PDF.
Here is my code:

Render(builder, Color.Red, new SizeF(12, 12));

///


/// Renders an elise to the specified builder.
///
/// The builder.
/// The color.
/// The size.
private static void Render(DocumentBuilder builder, Color color, SizeF size)
{
//string cacheKey = "LampCache_" + size.Width + "_" + size.Height + "_" + color.ToString();

//Lookup in cache
byte[] img = null; //= (byte[])HttpRuntime.Cache[cacheKey];

if (img == null)
{
RectangleF rect = new RectangleF(new PointF(0, 0), size);
RectangleF rect2 = RectangleF.Inflate(rect, -1, -1);

using (MemoryStream stream = new MemoryStream())
using (Bitmap bmp = new Bitmap(1, 1, PixelFormat.Format24bppRgb))
using (Graphics gTmp = Graphics.FromImage(bmp))
{
System.IntPtr hdc = gTmp.GetHdc();

using
(Metafile metafile = new System.Drawing.Imaging.Metafile(stream, hdc, rect, System.Drawing.Imaging.MetafileFrameUnit.Pixel, System.Drawing.Imaging.EmfType.EmfPlusDual))
using (Graphics g = Graphics.FromImage(metafile))
using (LinearGradientBrush b = new LinearGradientBrush(rect2, color, Color.White, LinearGradientMode.BackwardDiagonal))
{
try
{
g.FillEllipse(b, rect2);
g.DrawEllipse(Pens.Black, rect2);
}
finally
{
gTmp.ReleaseHdc(hdc);
}
}
img = stream.GetBuffer();

//Cache image for 5 sec
//HttpRuntime.Cache.Insert(cacheKey, img, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 0, 5));
}
}
builder.InsertImage(img, ConvertUtil.PixelToPoint(size.Width), ConvertUtil.PixelToPoint(size.Height));
}

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I managed to reproduce the problem on my side and created new issue #6913 in our defect database. I will notify you as soon as it is fixed.

Best regards.

The issues you have found earlier (filed as 6913) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by alexey.noskov.

The issues you have found earlier (filed as 1146) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(39)

The issues you have found earlier (filed as WORDSNET-1941) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.