A generic GDI exception during PDF to TIFF conversion can occur for several reasons. Here are some troubleshooting steps you can take:
Check File Permissions: Ensure that your application has the necessary permissions to read the PDF file and write the TIFF file to the specified directory.
Verify Input File: Make sure the PDF file is not corrupted. Open it with a PDF viewer to confirm it displays correctly.
System Resources: Ensure your system has enough memory and resources available, as GDI exceptions can occur when resources are low.
Correct Output Path: Verify that the output path for the TIFF file is valid and writable.
Update Aspose.PDF Library: Ensure you are using the latest version of the Aspose.PDF library, as newer releases may fix bugs.
Use Try-Catch Blocks: Wrap your conversion code in try-catch blocks to catch specific exceptions and log detailed error messages for further diagnosis.
Investigate Image Settings: If you are using specific settings for the image conversion (like resolution, color depth, etc.), try simplifying them to see if the error persists.
Check for GDI+ Issues: If your application runs in a restricted environment (like a web application), you might face GDI+ limitations. Consider running your code in a different environment to isolate the issue.
If the problem continues after checking these factors, consider reaching out to Aspose support with detailed information about your environment and the specific code snippet you are using for the conversion.
Hi, we have checked all the factors that you indicated, but error persist.
Our environment is on Azure app service, but also locally with this specific PDF fails.
here the complete code snippet:
try
{
_logger.Log("ConvertPDFVectorToPDFRasterMulti DOCUMENT: " + requestObj.FileName + " START", Logger.LogLevels.DEBUG);
List<MemoryStream> pdf_streams = new List<MemoryStream>();
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(streamInput);
bool IsLandscape = IsPageLandscape(pdfDocument.Pages.First());
var bookmarkEditor = new Aspose.Pdf.Facades.PdfBookmarkEditor();
bookmarkEditor.BindPdf(pdfDocument);
MemoryStream streamBookmark = new MemoryStream();
bookmarkEditor.ExportBookmarksToXML(streamBookmark);
Resolution resolution = new Resolution(_conversionConfig.Tiff_DPI);
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.None;
tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Default;
tiffSettings.Shape = IsLandscape ? ShapeType.Landscape : ShapeType.Portrait;
tiffSettings.SkipBlankPages = _conversionConfig.Tiff_SkipBlankPages;
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
using (ZipArchive oArchive = new ZipArchive(streamOutput, ZipArchiveMode.Create, true))
{
int idx = 0;
using (MemoryStream streamTiff = new MemoryStream())
{
tiffDevice.Process(pdfDocument, streamTiff);
using (var bitmap = new System.Drawing.Bitmap(streamTiff))
{
// Convert multi page or multi frame TIFF to multi page PDF
var dimension = new FrameDimension(bitmap.FrameDimensionsList[0]);
var frameCount = bitmap.GetFrameCount(dimension);
// Iterate through each frame
for (int frameIdx = 0; frameIdx <= frameCount - 1; frameIdx++)
{
using (var document = new Aspose.Pdf.Document())
{
var page = document.Pages.Add();
bitmap.SelectActiveFrame(dimension, frameIdx);
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Right = 0;
page.PageInfo.Margin.Left = 0;
using (var currentImage = new MemoryStream())
{
bitmap.Save(currentImage, ImageFormat.Tiff);
var imageht = new Aspose.Pdf.Image
{
ImageStream = currentImage,
//Apply some other options
//ImageScale = 0.5
};
page.PageInfo.Height = imageht.BitmapSize.Height;
page.PageInfo.Width = imageht.BitmapSize.Width;
page.Paragraphs.Add(imageht);
using (var pagePdfstream = new MemoryStream())
{
// save pdf in memory
document.Save(pagePdfstream);
pagePdfstream.Seek(0, SeekOrigin.Begin);
var pdfSheetName = sheetNames[idx];
if (!pdfSheetName.EndsWith(".pdf")) pdfSheetName += ".pdf";
ZipArchiveEntry oEntry = oArchive.CreateEntry(pdfSheetName);
using (var entryStream = oEntry.Open())
pagePdfstream.CopyTo(entryStream);
idx++;
}
}
}
GC.Collect();
}
}
}
}
_logger.Log("ConvertPDFVectorToPDFRasterMulti DOCUMENT: " + requestObj.FileName + " END", Logger.LogLevels.DEBUG);
streamOutput.Seek(0, SeekOrigin.Begin);
return streamOutput;
}
catch (Exception e)
{
_logger.Log("ConvertPDFVectorToPDFRasterMulti DOCUMENT: " + requestObj.FileName + " ERROR: " + e.ToString(), Logger.LogLevels.ERROR);
return null;
}
Have you tried using the latest version i.e. 25.10? We have tested using it and could not replicate the issue. The TIF images were generated without any error. Are you using the API in non-Windows environment? If so is the case, please uninstall existing Aspose.PDF for .NET from your project and install Aspose.PDF.Drawing for .NET instead. Please feel free to share some more information if error still persists, so that we can further proceed to assist you accordingly.
We have tried using Aspose.PDF 25.10, we are using .NET Core 8 on windows environment, we are still having error.
We have tried using Aspose.PDF.Drawing 25.9 with success!!
But wich version is correct to use, in our scenario? We manipulate PDF derived from DWG conversion, so vector graphical entities, no forms or fields.
I’m sorry, with Aspose.PDF.Drawing 25.9 we have success, but output pdf are 16/18 5Kb blank pdf, I attach zipped output. test Aspose.PDF.Drawing 25.9.zip (1.9 MB)
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): PDFNET-60919
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.