Fields in Word documents are not output


#1

Hello,

When saving an image to a stream with the Document.Save method of Aspose.Words for .NET
version 18.7, the field code “eq \ o \ ad (12345, )” in the Word document is not output.
How do I output the field code as an image?

In Version 17.6, the Document.Save method raised an exception ‘System.NullReferenceException’.

I have attached the original Word file and converted Jpeg Images.
No0030.zip (14.9 KB)

This is my code.

try
{
    using (MemoryStream docStream = new MemoryStream(File.ReadAllBytes("c:\\work\\sample.docx")))
    {
        Document document = new Document(docStream);
        {
            var pageInfo = document.GetPageInfo(0);
            Size pixelSize = pageInfo.GetSizeInPixels(1.0f, 180);

            // set pase option
            var options = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg);
            options.PageCount = 1;
            options.Resolution = 150;
            options.PageIndex = 0;
            using (MemoryStream imgStream = new MemoryStream())
            {
                // save
                // versin17.6:'System.NullReferenceException' occur.
                document.Save(imgStream, options);
                imgStream.Position = 0;
                using (Bitmap bitmap = new Bitmap(imgStream))
                {
                    bitmap.SetResolution(150, 150);
                    bitmap.Save("c:\\work\\sample.jpg");
                }
            }
        }
    }

}
finally
{
}

#2

@PFU.DSOL2,

Thanks for your inquiry. The EQ field does not render in output .jpeg when Document.GetPageInfo() method is called. Please use following code example to get the correct output.

Document document = new Document(MyDir + "sample.docx");
 
// set pase option
var options = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg);
options.PageCount = 1;
options.Resolution = 150;
options.PageIndex = 0;
document.Save(MyDir + "out.jpg", options);

For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17135. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.


#3

Thanks for your reply,

Sorry but the sample code I posted before was wrong.
The following code is correct.

using (MemoryStream docStream = new MemoryStream(File.ReadAllBytes("c:\\work\\sample.docx")))
{
    // Convert .docx file to JPEG.
    Document document = new Document(docStream);
    {
        // set pase option
        var options = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg);
        options.PageCount = 1;
        options.Resolution = 100;
        // save
        for (int i = 1; (i <= document.PageCount) && (i <= 100); i++)
        {
            options.PageIndex = i - 1;
            string filename = string.Format(@"c:\\work\\sample{0:D4}.jpg", i);
            document.Save(filename, options);
        }
    }
}

When you refer to document.PageCount property, characters in the EQ field are not output.
We need a reference to the document.PageCount property.On the other hand, if you do not refer to the document.PageCount property,

characters in the EQ field are output. However, those characters are not justified in the same as they are displayed on the Word screen.

I have attached the original Word file and converted Jpeg Images.
No0030-2.zip (19.9 KB)


#4

@PFU.DSOL2,

Thanks for your inquiry. We have logged this problem in our issue tracking system as WORDSNET-17183. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.