Tiff conversion and compression does not seem to work in .NET

I have been unable to save TIFFs in any compression format other than LZW using the Conversion API. I've tried G4 and RLE but it always appears to result in an LZW TIFF. G3 or G4 would be the best option for us but LZW is, unfortunately, the worst option in our case.

I'm setting TiffOptions.Compression to various members of the enumeration.

Here's the complete code I'm using in case I'm making some kind of mistake:

var options = new NamedValueCollection(parameters.Options);
var outputType = options.GetValue("OutputFileFormat", "image/tiff");
var config = new ConversionConfig();
var conv = new ConversionHandler(config);
var imageSaveOptions = new ImageSaveOptions
{
ConvertFileType = GetConvertFileType(outputType),
OutputType = OutputType.Stream, // Using streaming for the result. See comment below.
PageMode = false, // false seems to indicate to put all pages in a single file. Docs said it defaults to false--it doesn't.
Grayscale = options.GetValue("MakeGrayScale", true), // Let's go grayscale for now. TODO: Maybe another option?
CustomName = Path.GetFileName(parameters.Target.File), // When creating an output file in OutputPath, it used this name. We're not using that option but the docs implied
// it may created a cached file so I wanted the name to be unique and identifiable if there are later issues.
TiffOptions = new TiffOptions { Compression = options.GetValue("Compression", TiffOptions.TiffCompression.Ccitt4) }
};
var loadOptions = new LoadOptions();
using (var source = File.OpenRead(parameters.Source.File)) // Don't use the file name as a source or it will assume the format based on the extension. Use a stream to hide the extension so they make no assumption.
{
using (var destination = File.OpenWrite(parameters.Target.File))
{
// Tell it to return a stream by setting the ImageSaveOptions.OutputType to Stream
// and then call the generic function with a Stream type param. The other option is string in which case it puts it in the
// CoversionConfig.OutputPath folder but that had two issues: yet another file to delete and the function often returned null
// instead of said path. I'm not sure what I was doing wrong but the stream version has been reliable without further research.
using (var result = conv.Convert(source, loadOptions, imageSaveOptions))
{
// Transfer from the returned stream to the destination file.
foreach (var chunk in result.GetChunks(16384))
destination.Write(chunk, 0, chunk.Length);
}
}
}

Thanks
-Jonathan

@jisabell

Thank you for your inquiry.

We are sorry to hear that you are facing such issue. We have reproduced this scenario at our end and sharing this with product team for resolution. Once we have any update regarding this issue we will notify you here.

Thank you for your patience.

Warm Regards,

@jisabell,

We are pleased to apprise you that your reported issue (CONVERSIONNET-2042) is resolved. The fix is available in 17.9.0 version of the API. Please download and evaluate the latest release.

Hi,

Thanks for the update. I will give it a shot when I finish my current task.

-Jonathan

@jisabell,

You are welcome. Please feel free to post, if you face any further issues.

Hi,

I’m still not seeing version 17.9 version of groupdocs-conversion-dotnet available via NuGet even when allowing pre-release versions. Will this be coming out soon?

Thanks
-Jonathan

@jisabell,

GroupDocs.Conversion for .NET 17.9.0 is already released. See NuGet package here. You can also get DLL from GroupDocs public API download page. However, the latest version of the API is 17.11. We’d recommend you to utilize latest release in your project.

It’s not showing anything greater than 17.8.0 available for my project in the package manager. Seems odd.

@atirtahir3,

So it appears you all recently changed the name of the nuget package from “groupdocs-conversion-dotnet” to “GroupDocs.Conversion”. “groupdocs-conversion-net” only goes up to 17.8.0.

Anyway, changing the dependencies really quickly on my machine, updating per the obsolesced properties and methods, and running a sample image through, it appears to now output my requested G4 TIFF.

I will have to change the dependencies of my NuGet package and do a couple builds tonight for it to be ready for QA tomorrow. Hopefully they can get to it tomorrow but, again, in my quick test it seemed to work perfectly.

One last thing hopefully: Is there a place where I can see what the changes were in the various versions? Do you recommend simply using the latest version?

Thanks!
-Jonathan

@jisabell,

We are pleased to hear that.

Yes, you can see what changes were made or introduced in different releases/versions in release notes of the API.

Yes, you can see what changes were made or introduced in different releases/versions in release notes1 of the API.

Thanks for that. Very well organized. Kudos.

QA was good with my new version based on your fix. Thanks again!
-Jonathan

@jisabell.

You are welcome.