Doc to Tiff conversion

Hi,

I am using ASPOSE.WORDS for Doc/Docx/Txt to Tiff conversion. while converting the file i want to set the properties like

Color: Black and white
Coding Format: MH
Resolution: 204*196, 204 * 98, 200 * 200, 200 * 100
Page Data: 1728 pixels per line

below is my test code but by setting this it is not works for me for your reference i am attaching a test targeted tiff file.

Document doc = new Document(@"C:\Test\Test.docx");
ImageSaveOptions opt = new ImageSaveOptions(SaveFormat.Tiff);
opt.ImageColorMode = ImageColorMode.BlackAndWhite;
opt.TiffBinarizationMethod = ImageBinarizationMethod.Threshold;
opt.TiffCompression = TiffCompression.None;
opt.UseAntiAliasing = true;
opt.Resolution = 200;
opt.UseHighQualityRendering = true;
doc.Save(@"C:\Test\aspDocTtiff.tif", opt);

Also how can set the width and height of the tiff file.

Thanks & Regards
Manoj Surve

Doc/Docx/Txt to Tiff conversion In ImageSaveOptions How to set resolution while saving image to tiff (204*196, 204 * 98, 200 * 200, 200 * 100) Color: Black and white Coding Format: MH Page Data: 1728 pixels per line

Hi Manoj,

Thanks for your inquiry. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v14.8.0) from here and let us know how it goes on your side.

You are using the correct code of Aspose.Words. I suggest you please use ImageSaveOptions.TiffCompression as TiffCompression.Ccitt4 in your code. Could you please share the problematic sections of your output Tiff file? We will investigate the issue and provide you more information.

*ManojTelesoft:

Coding Format: MH*

Could you please share some detail about coding format? We will then provide you more information about this query along with code.

*ManojTelesoft:

Also how can set the width and height of the tiff file.*

Please use following code example to achieve your requirements. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
// Render first page of Word document to an image stream
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
options.PageIndex = 0;
options.PageCount = 1;
MemoryStream imgStream = new MemoryStream();
doc.Save(imgStream, options);
// Insert the image stream into a temporary Document instance.
Document temp = new Document();
DocumentBuilder builder = new DocumentBuilder(temp);
Shape img = builder.InsertImage(imgStream);
// Resize the image as per your needs
img.Width = 64;
img.Height = 64;
// Save the individual image to disk using ShapeRenderer class
ShapeRenderer renderer = img.GetShapeRenderer();
renderer.Save(MyDir + "Out.tiff", new ImageSaveOptions(SaveFormat.Tiff));

Hi,

Thanks for your reply, I tried this code but it not work for me. Basically i want to convert doc to tiff file which can support to the FAX. The MH format is basically G3 format mainly use for the FAX.

I am using fax protocol T.30 and T.4, allowed to transmit MH data and Tiff files.

The Tiff file is the mainstream one used to store fax data, which can be widely
used and is easy to read, archive and modify. And the Tiff file supported by fax
channels has the following properties.

Color: Black and white
Coding Format: MH
Resolution: 204*196, 204 * 98, 200 * 200, 200 * 100
Page Data: 1728 pixels per line

G3 fax are
204 dots per inch(dpi) horixontally and 98 dpi(196 dpi optionally, in fine detail mode) vertically.

Hi Manoj,

Thanks for sharing the detail. You can set resolution for the generated images using ImageSaveOptions.Resolution property and set the color mode for the generated images using ImageSaveOptions.ImageColorMode property.

Regarding Coding Format and Page Data, I have logged a feature request as WORDSNET-10905 in our issue tracking system. Our development team will look into the
possibility of implementation of this feature. Once we have
any information about this feature, we will update you via this forum thread.

Please let us know if you have any more queries.

Hi Manoj,

Thanks for your patience.

Aspose Words relies on GDI+ for rendering images and it seems that GDI+ doesn’t support of setting “Coding format” for tiff images. However value “MH” can be set by default.

Page data seems to be just width of the image. I hope following code example will produce output that you expect.

Document doc = new Document(MyDir + "in.docx");
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
options.Resolution = 200;
options.TiffCompression = TiffCompression.Ccitt3;
doc.Sections[0].PageSetup.PageWidth =
ConvertUtil.PixelToPoint(ConvertUtil.PixelToNewDpi(1728, options.Resolution, 96));
doc.Save(MyDir + "Out.tiff", options);

Please let us know if you have any more queries.

Hi Tahir,

Thanks for your kind support.

Document doc = new Document(@"C:\Test\Test.docx");
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff); 
options.PageIndex = 0; 
options.PageCount = 1; 
options.Resolution = 204; 
MemoryStream imgStream = new MemoryStream(); 
doc.Save(imgStream, options); 
// Insert the image stream into a temporary Document instance. 
Document temp = new Document(); 
DocumentBuilder builder = new DocumentBuilder(temp); 
Aspose.Words.Drawing.Shape img = builder.InsertImage(imgStream); 
// Resize the image as per your needs 
img.Width = 1296; 
img.Height = 857;
ImageSaveOptions opt = new ImageSaveOptions(SaveFormat.Tiff); 
opt.TiffCompression = TiffCompression.Ccitt3; 
// Save the individual image to disk using ShapeRenderer class 
ShapeRenderer renderer = img.GetShapeRenderer(); renderer.Save(@"C:\Test\Out.tif", opt);

this code is work for me and it gives me desire output as per my requirements.
but in above code it generate a tiff for a given pageIndex only.
How can i make a single tif file from a given doc/docx/txt file with multiple pages.

Thanks

Hi Manoj,

Thanks for your inquiry. Please set the value of ImageSaveOptions.PageIndex to Document.PageCount to get the required output. See the following highlighted code snippet.

Document doc = new Document(MyDir + "in.docx");
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
options.Resolution = 200;
options.TiffCompression = TiffCompression.Ccitt3;
options.PageCount = doc.PageCount;
options.PageIndex = 0;
foreach (Section section in doc.Sections)
{
    section.PageSetup.PageWidth = ConvertUtil.PixelToPoint(ConvertUtil.PixelToNewDpi(1728, options.Resolution, 96)); 
}
doc.Save(MyDir + "Out.tiff", options);