Need Specific C# code to change dimensions of tif file

Hi Support,
I am a new register user of Aspose Total for .net and have recently purchased it. I am running the current version
I need to convert a word doc to tif and resize the tif file to a particular size for a fax server. I have looked at other posts on this but cannot find specific code examples to do this only tips to try rendertosize or rendertoscale which don’t help.
Here is my sample code which in part is your example code. I added code to resize to width:1728pixels and Height 2320pixels, but this has no effect. Can you help ?

namespace SaveAsMultipageTiff
    class Program
        static void Main()
            // Sample infrastructure.
            string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string dataDir = Path.GetFullPath(Path.Combine(exeDir, @"..\..\Data\"));
                    // Open the document.
                    Document doc = new Document(dataDir + "TestFile.doc"); Aspose.Words.Saving.ImageOptions imgOptions = new Aspose.Words.Saving.ImageOptions(); imgOptions.Resolution = 300; imgOptions.TiffCompression = Aspose.Words.Saving.TiffCompression.Ccitt4; doc.Sections[0].PageSetup.PageHeight = 2320; doc.Sections[0].PageSetup.PageWidth = 1728; doc.SaveToImage(0, doc.PageCount, dataDir + "TestFile.tiff", imgOptions);


Thanks for your inquiry. I think in your case you can use RenderToSize method. But since in your case you need to generate a multipage tiff, you should also create this tiff on the fly. For example see the following link to learn how to create a multipage tiff:
Hope this helps.
Best regards.

Thanks Alexey for the code, BUT even this example doesn’t show me how to set the width and height of the tif file. Do you have an EXAMPLE to do this rather that just saying use RenderToSize.

Hi there,
Thanks for this additional information.
You can set the specific resolution for your rendered image by using the code below:

// Convert resolution between the default and the specified DPI
doc.Sections[0].PageSetup.PageHeight = ConvertUtil.PixelToPoint(ConvertUtil.PixelToNewDpi(2320, imgOptions.Resolution, 96));
doc.Sections[0].PageSetup.PageWidth = ConvertUtil.PixelToPoint(ConvertUtil.PixelToNewDpi(1728, imgOptions.Resolution, 96));

There is extra code needed because the resolution is not the default (96). This code will produce an image with the dimensions almost exactly as 1728x2320.

Thanks that worked well 99% except the resultant dimensions of the tif were one pixel out 1727x2321 instead of 1728 x 2320 not sure why. Any ideas ?

Hi Clive,
Thank you for this additional information.
You are correct, it does appear to be a pixel or two off in some situations. I believe this is due to a slight bit of precision being lost somewhere in the calcuation where the resolution is converted. I have taken a look and I believe using this method below instead will be more accurate.

doc.Sections[0].PageSetup.PageHeight = ConvertUtil.PixelToPoint(2320, imgOptions.Resolution);
doc.Sections[0].PageSetup.PageWidth = ConvertUtil.PixelToPoint(1728, imgOptions.Resolution);

This creates an image of those exact dimensions on my side.
If you have any further queries please feel free to ask.

Hi Adam,
That worked well. Thankyou.
While you are familiar with what I am trying to do if you don’t mind I thought I would draw your attention to another rendering problem I have. The example testfile.docx I am trying to convert via this code has some logos in it. Part of the Logo is in red and this is getting rendered to white in the tif file not a shade of grey as I would expect when the compression is rle, ccitt3 or ccitt4. We need these compression types because the tiff will be sent to a fax gateway eventually. Is there anything in the render process that can be tuned to represent the logo correctly. Its odd as its only this logo that its having problems with.
I have attached the sample document for you to test with the code.

Hi Clive,
Thanks for bringing this to our attention. I have managed to reproduce the issue on my side. Your issue has been linked and we will look into fixing this in a future versions. We will keep you informed of any developments regarding this issue.
In the mean time you can fix this issue by inserting these images in MS Word using the “Windows MetaFile” format instead. The text in these images will rendered correctly when using grayscale compression. I have sent the fixed up document to your inbox.

The issues you have found earlier (filed as WORDSNET-3774) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.