DOCX to TIF - Multi-Page

We are looking at your evaluation tool and want to know if there is a way to convert a multiple-page DOCX or DOC file to a Multi-Page TIF. Right now, the code we have tried only converts that last page. I am unsure if this is because we are using an evaluation version of the tool or if I don’t have the settings I need. TIA for the help.

Here is my sample code.

string inputFileName = @"D:\Testing\Imports\MultiPageDocument.docx";
	string outputFileTemplate = Path.ChangeExtension(inputFileName, "tif");

	Func<int, Stream> getPageStream = page => new FileStream(string.Format(outputFileTemplate, page), FileMode.Create);
	
	using (Converter converter = new Converter(inputFileName))
	{

		ImageConvertOptions options = new ImageConvertOptions
		{
			Format = ImageFileType.Tiff,
			Grayscale = true,
			UsePdf = false,
			TiffOptions = new TiffOptions
			{
				Compression = TiffCompressionMethods.Ccitt4,
			}
			
		};

		converter.Convert(getPageStream, options);
	}
1 Like

@MarkMooreNts
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CONVERSIONNET-6884

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@MarkMooreNts

In order to convert a multipage source file into a multipage result file (TIF), the following Func should be used:

Func<Stream> getDocumentStream = () => new FileStream(string.Format(outputFileTemplate), FileMode.Create);

and the complete code snippet is:

//C# code to convert DOCX file to multipage TIF
// Define the input file path for the Word document
string inputFileName = @"D:\Testing\Imports\MultiPageDocument.docx";

// Construct the output file path by changing the extension to "tif"
string outputFileTemplate = Path.ChangeExtension(inputFileName, "tif");

// Create a delegate function that returns a new FileStream for the output file
Func<Stream> getDocumentStream = () => new FileStream(string.Format(outputFileTemplate), FileMode.Create);

// Create a new Converter instance and use it to convert the Word document to TIFF
using (Converter converter = new Converter(inputFileName))
{
    // Define the conversion options
    ImageConvertOptions options = new ImageConvertOptions
    {
        // Set the output file format to TIFF
        Format = ImageFileType.Tiff,

        // Convert the document to grayscale
        Grayscale = true,

        // Disable the use of PDF conversion
        UsePdf = false,

        // Set the TIFF compression method to CCITT4 (Group 4 Fax)
        TiffOptions = new TiffOptions
        {
            Compression = TiffCompressionMethods.Ccitt4,
        }
    };

    // Perform the conversion using the defined options and the getDocumentStream delegate
    converter.Convert(getDocumentStream, options);
}

Take a look at this output - output.zip (4.0 KB). Let us know if issue persists.

WOW, thanks. It was staring me right in the face, and I didn’t see it.

Thanks.

1 Like

@MarkMooreNts

You are welcome.