Free Support Forum - aspose.com

Garbled text in output

I'm using the code below to generate a Word doc containing only an image from an ASP.NET app. As well as the image, the resulting doc contains the Evaluation Use Only warning (fair enough), but then also about six random characters. Do these characters disappear when licensed or is there a problem?

Cheers,

Max Christian

Dim doc As New Aspose.Word.Document
Dim docB As New Aspose.Word.DocumentBuilder(doc)
Dim img As New Bitmap("filenameOfExistingImage.PNG")

docB.PageSetup.PaperSize = Aspose.Word.PaperSize.A4
Dim scale As Double = docB.PageSetup.PageWidth / img.Width
docB.InsertImage(img, img.Width * scale, img.Height * scale)

Dim outFilename As String = "Somefile.DOC"
doc.Save(outFilename, Aspose.Word.SaveFormat.FormatDocument, Aspose.Word.SaveType.OpenInWord, Response)

http://www.aspose.com/forums/ShowPost.aspx?PostID=12548

Sorry, did have a quick look before posting but somehow managed to miss that.

I have one other problem: the code I quoted results in an image that is wider than the page margins. I tried subtracting PageSetup.LeftMargin/RightMargin from PageWidth, but that results in an image which is much too small.

Any ideas?

Cheers,

Max Christian

DocumentBuilder accepts measurements in points (1/72 inch) but your image width and height are in pixels (normally 1/96 inch). You need to convert from pixels to points using something like this:

///

/// Convers pixel to point at 96 dpi.

///

internal static double PixelToPoint(double pixels)

{

return ((pixels / 96) * 72);

}