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

Free Support Forum - aspose.com

Word to TIF conversion with specific attributes causes truncated output

Hi Support,

Can you comment on the attached code which needs to convert any .doc or docx document to a tif file with width : 1728pixels x height 2320 pixels, resolution : 300dpi, Compression CCITT4. This code did work in a previous vesrion of Aspose that I evaluated, I have since purchased a copy but the new version truncates the data in the resultant tiff. Can you advise whats wrong.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace TestAspose

{

class Program

{

static void Main(string[] args)

{

string infile = "c:\\junk\\Aspose.docx";

string outfile = "c:\\junk\\Aspose.tiff";

bool result = Word(infile, outfile);

if (result == false)

Console.WriteLine("Conversion did not work");

else

Console.WriteLine("Conversion complete");

}

public static bool Word(string inputfullpath, string outputfullpath)

{

//string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

//string dataDir = Path.GetFullPath(Path.Combine(inputdirectory, @"..\..\Data\"));

//Open the document.

bool ret = true;

try

{

Aspose.Words.Document doc = new Aspose.Words.Document(inputfullpath);

Aspose.Words.Saving.ImageSaveOptions imgOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Tiff);

imgOptions.Resolution = 300;

imgOptions.TiffCompression = Aspose.Words.Saving.TiffCompression.Ccitt4;

//Convert resolution between the default and the specified DPI

//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.

doc.Sections[0].PageSetup.PageHeight = Aspose.Words.ConvertUtil.PixelToPoint(Aspose.Words.ConvertUtil.PixelToNewDpi(2320, imgOptions.Resolution, 96));

doc.Sections[0].PageSetup.PageWidth = Aspose.Words.ConvertUtil.PixelToPoint(Aspose.Words.ConvertUtil.PixelToNewDpi(1728, imgOptions.Resolution, 96));

Aspose.Words.Saving.SaveOutputParameters p = doc.Save(outputfullpath, imgOptions);

}

catch (Exception)

{

ret = false;

}

return ret;

}

}

}

Thanks Clive

Hi Clive,


Thanks for your inquiry and sorry for the delayed response. Perhaps, in your case addition of the following code would be helpful to you:

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

foreach (Table tab in
doc.FirstSection.Body.Tables)
{
tab.AutoFit(AutoFitBehavior.AutoFitToContents);
}

Aspose.Words.Saving.SaveOutputParameters p = doc.Save(outputfullpath,
imgOptions);

Please let me know if I can be of any further assistance

Best Regards,

Can support please provide me with a code sample to convert word to tiff with dimensions width 1728pixels x height 2320 pixels, resolution : 300dpi, Compression CCITT4. The above code does not work. Need this urgently.

Clive

Thanks I will try this code and get back to you.

Clive

I am getting an error with the additional code you suggested that the namespace name 'Table ' could not be found and AutoFitBehaviou does not exist in the current context.

Can you advise please.

Hi
Clive,


Thanks for your inquiry. Perhaps you’re using an older version of Aspose.Words. I would suggest you please upgrade to the latest version of Aspose.Words i.e. v11.0.0. Moreover, please read the following article on How-to: Migrate to Aspose.Words 10.5 or Higher:
http://docs.aspose.com/display/wordsnet/How+to++Migrate+to+Aspose.Words+10.5+or+Higher

I hope, this will help.

Best Regards,

Thanks Awais,

I have upgraded to v11.0.0 as suggested and I have passed our test document through the test code listed earlier in this ticket and I get an out of memory exception when attempting to save to tiff. The virtual machine has 16GB of memory and 13GB is available. I have attached the test document for you to duplicate the problem. I hope you can fix this quickly as we have purchased an OEM licence and I have a large project waiting for this functionality.

Thanks

Clive

Hi,

Thanks for your inquiry. I have answered, here in this thread, to a similar question of yours. If we can help you with anything else, please feel free to ask.

Best Regards,