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

Free Support Forum - aspose.com

Convert doc/docx to JPG problem

I want to convert doc/docx to pdf, and then convert it to thumbnail. But all chinese characters in original doc file change to trash code after convert it to pdf, how to solve this problem? The product I used is 'aspose.word aspose.pdf.kit aspose.pdf ’
In addition, is there any way to set the size, width and height of the thumnail?
The samp code is:

Document doc = new Document(@"C:\Documents and Settings\Administrator\Desktop\MyDocument.doc");
doc.Save(@"C:\Documents and Settings\Administrator\Desktop\MyDocument.xml", SaveFormat.AsposePdf);
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML(@"C:\Documents and Settings\Administrator\Desktop\MyDocument.xml", null);
pdf.IsImagesInXmlDeleteNeeded = true;
pdf.Save(@"C:\Documents and Settings\Administrator\Desktop\MyDocument.pdf");

// Convert Each page of a pdf Document to a image.
PdfConverter converter = new PdfConverter();
converter.BindPdf(@"C:\Documents and Settings\Administrator\Desktop\MyDocument.pdf");
String prefix = @"C:\Documents and Settings\Administrator\Desktop\";
String suffix = ".jpg";
int imageCount = 1;
while (converter.HasNextImage())
    if (imageCount == 5)
    converter.GetNextImage(prefix + imageCount + suffix, ImageFormat.Jpeg);

Thank you for your inquiry.
I have reproduced the issue. It requires cooperation with Aspose.Pdf team to be solved. I cannot promise to help you fast. Asian languages support has many limitations in our products. Let’s wait what Aspose.Pdf team answers. I’ll keep you informed of any progress.
To set width and height of a thumbnail you can try another overload of GetNextImage():

Thanks for your help!
I used GetNextImage(Stream outputStream, ImageFormat format, int resolutionX, int resolutionY, int quality) function to convert pdf to thumbnail but created jpg image’s width and height not i wanted. what wrong wiht it?

Thanks fro your inquiry. You can try using GetTubbnaulImage method.

Image outputImage = sourceImage.GetThumbnailImage(targetWidth, targetHeight, null, new IntPtr());

Also you can try using the following method.

/// Resize source image to specifed sze
/// Source image
/// Target width
/// Target height
/// Resized image
public static Image ResizeImage(Image sourceImage, int targetWidth, int targetHeight)
    float ratioWidth = (float)sourceImage.Width / targetWidth;
    float ratioHeight = (float)sourceImage.Height / targetHeight;
    if (ratioWidth > ratioHeight)
        targetHeight = (int)(targetHeight * (ratioHeight / ratioWidth));
        if (ratioWidth < ratioHeight)
            targetWidth = (int)(targetWidth * (ratioWidth / ratioHeight));
    // create target image
    Bitmap targetImage = new Bitmap(targetWidth, targetHeight, PixelFormat.Format24bppRgb);
    targetImage.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
    // set transform parameters 
    using (Graphics g = Graphics.FromImage(targetImage))
        g.CompositingQuality = CompositingQuality.HighQuality;
        g.SmoothingMode = SmoothingMode.HighQuality;
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        // resize image
        Rectangle rc = new Rectangle(0, 0, targetImage.Width, targetImage.Height);
        g.DrawImage(sourceImage, rc);
    return (Image)targetImage;

I hope this could help you.
Best regards.


I am a developer of Aspose.Pdf. I have tried to convert your doc into pdf. I found the xml is not correctly generated. I think this should be a bug in Aspose.Words. Thanks.

Best regards.

Thank you for your expertise. I have logged the problem with encoding as #4597 in our defect database. We’ll investigate it and provide more information on any progress.
As a workaround you can try re-saving this file again as RTF in MS Word. It helped me to created well-formed Aspose.Pdf XML containing proper Unicode characters but I’m unable to check whether it converts to PDF correctly without having Asian languages support. I asked Aspose.Pdf team leader about this. Since you are working with documents containing hieroglyphs you should get proper conversion result after the rtf2rtf roundtrip.

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