Hi dear Aspose support,
for a project, we are converting email attachments to TIF. Some of the PDF files give us the exception below. I do know what causes the exception but I'm curious if you could give me some hints for a workaround.
I tried originally with using TiffDevice, where I got the GDI+ exceptions at first place and after that I tried using PdfConverter, just to see, that TiffDevice is used internally, which produces the same exceptions.
My code is:
private static bool ConvertPdfToTif(string sourceFilePath, string destinationFilePath, bool preserveColors, bool applyApplicationDpi = false)
{
//this is set as a workaround for a huge Aspose problem, which they already confirmed. If one tries to force an one bit color here,
//then the memory usage goes freaking wild and an OutOfMemory exception is thrown.
preserveColors = true;
var pdfConverter = new PdfConverter();
try
{
pdfConverter.BindPdf(sourceFilePath);
// Create Resolution object
var resolution300 = new Aspose.Pdf.Devices.Resolution(NumericConstants.ApplicationDPI);
var resolution96 = new Aspose.Pdf.Devices.Resolution(96);
// Create TiffSettings object
var tiffSettings = new Aspose.Pdf.Devices.TiffSettings();
tiffSettings.Compression = preserveColors ? Aspose.Pdf.Devices.CompressionType.LZW : Aspose.Pdf.Devices.CompressionType.CCITT4;
tiffSettings.Depth = preserveColors ? Aspose.Pdf.Devices.ColorDepth.Default : Aspose.Pdf.Devices.ColorDepth.Format1bpp;
tiffSettings.SkipBlankPages = false;
//Convert
pdfConverter.DoConvert();
pdfConverter.Resolution = applyApplicationDpi ? resolution300 : resolution96;
pdfConverter.SaveAsTIFF(destinationFilePath, tiffSettings);
return File.Exists(destinationFilePath);
}
catch (Exception exc)
{
SLogger.WriteError(exc, null, "Dateiname: " + sourceFilePath);
return false;
}
finally
{
pdfConverter.Close();
}
}
===Exception===
A generic error occurred in GDI+.
StackTrace : at System.Drawing.Image.SaveAdd(EncoderParameters encoderParams)
at aa.a.()
at Aspose.Pdf.Devices.TiffDevice.Process(Document document, Int32 fromPage, Int32 toPage, Stream output)
at Aspose.Pdf.Facades.PdfConverter.SaveAsTIFF(Stream outputStream, Int32 imageWidth, Int32 imageHeight, TiffSettings settings)
at Aspose.Pdf.Facades.PdfConverter.SaveAsTIFF(String outputFile, TiffSettings settings)
at TiS.DevGER.MR.KabelD.Common.Converting.IeAsposeConverter.ConvertPdfToTif(String sourceFilePath, String destinationFilePath, Boolean preserveColors, Boolean applyApplicationDpi) in c:\DEV\de_kabelDeutschland_dia\TiS.DevGER.MR.KabelD.Common\Converting\IEAsposeConverter.cs:line 528
Thanks in advance for the help!
Regards
Vasil Tonev