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

Free Support Forum - aspose.com

Issue while converting bigger size tiff file to pdf

Hello Everyone,
When I am trying to convert TIFF file of size 110 MB to PDF file, the ASPOSE library is throwing serialization error from calling desktop application. Its working perfect for small sized files. I have mentioned my code snippet in the below.

private static void ConvertTiffToPdf(string sourceFilePath, string targetFolderPath, string filename)
{
    using (var fs = new FileStream(sourceFilePath, FileMode.Open, FileAccess.Read))
    {
        using (var image = Aspose.Imaging.Image.Load(fs))
        {
            //Obtain default saving options defined for each image
            ImageOptionsBase exportOptions = new PdfOptions() { PdfCoreOptions = new Aspose.Imaging.FileFormats.Pdf.PdfCoreOptions() { Compression = PdfImageCompressionOptions.Ccitt4 }, UseOriginalImageResolution = true };

            image.Save(targetFolderPath.TrimEnd('\\') + $"\\{filename}.pdf", exportOptions);
        }
    }
}

Could you please suggest the optimal way to convert such big tiff files(110 MB) to PDF?
Thank you.

@ajayu,

I have a 2 part questiong for you.

Are you using Aspose.Imaging?

Or you will use Aspose.Pdf?

So I can move this post to the right forum.

@carlos.molina
I am using Aspose.Imaging.
Thanks.

@ajayu,

I will move this post to the right forum so you get the support you need.

@ajayu, you have few options to process occured issue:

  1. Try another options for PdfOptions (for example change compression), for example https://docs.aspose.com/imaging/net/manipulating-tiff-images/#export-tiff-to-pdf-set-dpi-for-exported-pdf or https://docs.aspose.com/imaging/net/convert-raster-image-to-pdf/
  2. Also you can try use BufferSizeHint to limit memory usage for loaded image as here https://docs.aspose.com/imaging/net/manipulating-jpeg-images/#memory-strategy-optimization or here described https://docs.aspose.com/imaging/net/manipulating-tiff-images/#memory-strategy-optimization

@samer.el-khatib
As you suggested I have tried both option 1 and option 2. It is working for smaller files only.

Option 1 code snippet:

using (var fs = new FileStream(sourceFilePath, FileMode.Open, FileAccess.Read))
{
using (var image = Aspose.Imaging.Image.Load(fs))
{
//Obtain default saving options defined for each image
ImageOptionsBase exportOptions = new PdfOptions() { PdfCoreOptions = new Aspose.Imaging.FileFormats.Pdf.PdfCoreOptions() { Compression = PdfImageCompressionOptions.Ccitt4 }, UseOriginalImageResolution = true };

                image.Save(targetFolderPath.TrimEnd('\\') + $"\\{filename}.pdf", exportOptions);
            }
        }‚Äč

Error: IndexOutOfRangeException: Index was outside the bounds of the array.
Option 2 code snippet:
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(sourceFilePath,new Aspose.Imaging.LoadOptions { BufferSizeHint= 10 }))
{
//Obtain default saving options defined for each image
ImageOptionsBase exportOptions = new PdfOptions() { PdfCoreOptions = new Aspose.Imaging.FileFormats.Pdf.PdfCoreOptions()
{ Compression = PdfImageCompressionOptions.Ccitt4 }, UseOriginalImageResolution = true };

                image.Save(targetFolderPath.TrimEnd('\\') + $"\\{filename}.pdf", exportOptions);
            }

Its not throwing any error but image.save is keep on executing. I have waiter for more than an hour.

@ajayu, please provide your source file.Also please note in p.2 you set extremely small buffer 10 Mb only, this way it will work but will take too long time, you can increase your buffer size for example to 500 or 1000 mb and check results.