Hi,
2 documents are attached to this post. The first one hase been generated with aspose.word, the second is the same as the first but I inserted manually the image in chapter 13 from msword.
Please, could you tell me how to decrease file size generated by aspose.word.
I use this methode to insert image file, but the result is not acceptable :
Sub HandleMergeImageField(ByVal sender As Object, ByVal e As Aspose.Words.Reporting.MergeImageFieldEventArgs)
If e.FieldValue Is Convert.DBNull OrElse e.FieldValue = Nothing Then Exit Sub
If e.FieldName.Contains("ImgCertificat") Then
Dim a As String = ""
End If
Dim str() As String = Split(e.FieldName, " ")
Dim lg As Integer = 0 ’ Largeur maximale de l’image dans le rapport
Dim ht As String = 0 ’ Hauteur maximale de l’image dans le rapport
Dim Fic As String = ""
Dim spots As String = ""
mBuilder.MoveToMergeField(e.FieldName)
If str.Length > 2 Then ’ les largeurs et hauteurs sont passées
If IsNumeric(str(1)) Then lg = CInt(str(1))
If IsNumeric(str(2)) Then ht = CInt(str(2))
Else
’ On prend la largeur de la page
Dim a As Aspose.Words.Section = mBuilder.CurrentSection
lg = (a.PageSetup.PageWidth - a.PageSetup.RightMargin - a.PageSetup.LeftMargin)
ht = (a.PageSetup.PageHeight - a.PageSetup.TopMargin - a.PageSetup.BottomMargin)
End If
Dim st2() As String = Split(CStr(e.FieldValue), Chr(0))
Fic = st2(0).Trim
If Fic = "" Then Exit Sub
Dim fi As New IO.FileInfo(Fic)
If Not fi.Exists Then Exit Sub
Dim img As System.Drawing.Bitmap = New System.Drawing.Bitmap(Fic)
Threading.Thread.Sleep(200)
If st2.Length > 1 Then
spots = st2(1)
img = FormatSpots(img, spots)
End If
’ Reformater l’image pour tenir dans les hauteurs et largeurs
Dim sc1 As Single = 1
Dim sc2 As Single = 1
If lg = 0 Then lg = img.Width
If ht = 0 Then ht = img.Height
If lg < img.Width Then
sc1 = lg / img.Width
End If
If ht < img.Height Then
sc2 = ht / img.Height
End If
Dim sc As Single = Math.Min(sc1, sc2)
'imgc = New System.Drawing.Bitmap(img, img.Width * sc, img.Height * sc) ’ Image contenant la photo
'img.Dispose()
’ Règles :
’ Conserver l’image telle quelle et l’insérer à la taille de la zone d’impression
’ Adapter l’image à la taille de la zone d’impression
'If Not e.FieldName.ToLower.Contains("photo") Then
’ pas de réduction
'Dim img1 As System.Drawing.Bitmap = New System.Drawing.Bitmap(img, img.Width, img.Height)
'Dim sh As Aspose.Words.Drawing.Shape = mBuilder.InsertImage(img1, img1.Width * sc, img1.Height * sc)
'Else
‘’ Réduction
If sc > 1 Then
sc = 1
End If
Dim img1 As System.Drawing.Bitmap
img1 = New System.Drawing.Bitmap(CInt(img.Width * sc * 1.33 * 2), CInt(img.Height * sc * 1.33 * 2))
img1.SetResolution(96, 96)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(img1)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(img, New System.Drawing.Rectangle(0, 0, img1.Width, img1.Height), 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel)
g.Dispose()
Dim sh As Aspose.Words.Drawing.Shape = mBuilder.InsertImage(img1, img1.Width / 1.33 / 2, img1.Height / 1.33 / 2)
'Dim sh As Aspose.Words.Drawing.Shape = mBuilder.InsertImage(img1, img1.Width * sc, img1.Height * sc)
e.Image = Nothing
End Sub
Thanks you
Regards