Hello,
a small bug.
If you start from a *.doc (not docx), insert an svg image and save the file as *.doc, the image is blurry.
If you save as *.docx, the image is perfect.
Best regards
Luca
This is a testing code
class Program
{
static void Main(string[] args)
{
bool version_22_ck = Aspose.Words.BuildVersionInfo.Version.Contains("18.") ? false : true;
Aspose.Words.License license = new Aspose.Words.License();
string templatePath = "Test_SVG.doc";
string fileNamePath = "myimage.svg";
if (version_22_ck)
{
//versione 22.8
//verssione 23.7
license.SetLicense("Aspose.Words.NET.lic");
}
else
{
//versione 18.1
//versione 18.2
license.SetLicense("Aspose.Words.lic");
}
Aspose.Words.Document wordDocument = null;
wordDocument = new Aspose.Words.Document(templatePath);
//Create a list of the names of the bookmarks
List<string> lst_name = wordDocument.Range.Bookmarks.Cast<Aspose.Words.Bookmark>().Select(b => b.Name).ToList();
Aspose.Words.Bookmark bm = wordDocument.Range.Bookmarks[lst_name[0]];
string bm_name = bm.Name;
bm_name = "disegno_1";
Aspose.Words.Drawing.Shape shp = WordSupport.InsertImageIntoBookmark(wordDocument, bm_name, fileNamePath, rotation_mode: 1);
// per avere un'immagine di H=22 cm
//shp.Height = 623; -> conversione punti tipografici 1 pto = 0,0352778 cm con 72dpi
if (shp.Rotation == 0)
{
shp.Height = 623;
}
else
{
shp.Width = 623;
}
wordDocument.UpdateFields();
wordDocument.Save("Test_SVG_save.doc");
wordDocument.Save("Test_SVG_save.docx");
wordDocument = new Aspose.Words.Document("Test_SVG_save.docx");
wordDocument.Save("Test_SVG_save.pdf");
}
public static Aspose.Words.Drawing.Shape InsertImageIntoBookmark(Aspose.Words.Document document, string bookmarkName, string fileName, Aspose.Words.Drawing.WrapType wrapType = Aspose.Words.Drawing.WrapType.Inline, bool behindText = true, int rotation_mode = 0)
{
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(document);
builder.MoveToBookmark(bookmarkName);
Aspose.Words.Drawing.Shape shape = builder.InsertImage(fileName);
shape.WrapType = wrapType;
shape.BehindText = behindText;
//shape.RelativeHorizontalPosition = Aspose.Words.Drawing.RelativeHorizontalPosition.Page;
//shape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;
//shape.RelativeVerticalPosition = Aspose.Words.Drawing.RelativeVerticalPosition.Page;
//shape.VerticalAlignment = Aspose.Words.Drawing.VerticalAlignment.Center;
//rotation_mode: 0=non ruota, 1=se immagine ha forma orizzontale, viene ruotata in senso antiorario di 90° per assumere aspetto verticale, 2=se immagine ha forma verticale, viene ruotata ins enso orario di 90° per assumere aspetto orizzontale
// Rotation=-90 immagine viene ruotata di 90 gradi in senso antiorario
if (rotation_mode == 1 && (shape.Width > shape.Height))
{
shape.Rotation = -90;
}
else if (rotation_mode == 2 && (shape.Width < shape.Height))
{
shape.Rotation = 90;
}
return shape;
}
}