Hello,
Using this attached PDF fnac01.pdf, if we want to convert the page to a png (or svg or all other formats… ) the PngDevice.Process freeze the thread in the jpeg2k decode and never return…
You can reproduce the issue easily in the sample ConvertAllPagesToPNG :
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir + "fnac01.pdf");
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
using (FileStream imageStream = new FileStream(dataDir + "image" + pageCount + "_out" + ".png", FileMode.Create))
{
// Create PNG device with specified attributes
// Width, Height, Resolution, Quality
// Quality [0-100], 100 is Maximum
// Create Resolution object
Resolution resolution = new Resolution(300);
PngDevice pngDevice = new PngDevice(resolution);
// Convert a particular page and save the image to stream
pngDevice.Process(pdfDocument.Pages[pageCount], imageStream);
// Close stream
imageStream.Close();
}
}
// ExEnd:ConvertAllPagesToPNG
System.Console.WriteLine("PDF pages are converted to PNG successfully!");
fnac01.pdf (28.4 KB)
The process never end and take lots of CPU resources (100% of one cpu)
@tfipsrd
It seems that you are experiencing a freezing issue when trying to convert a PDF page to PNG format using the PngDevice.Process
method. This can happen due to various reasons, including the complexity of the PDF content or specific issues with the PDF file itself.
Here are a few suggestions to troubleshoot and potentially resolve the issue:
-
Check PDF Content: Ensure that the PDF file does not contain any corrupted images or unsupported formats that might cause the processing to hang. You can try opening the PDF in a viewer to see if it displays correctly.
-
Use Different Resolution: Sometimes, using a very high resolution can lead to performance issues. Try reducing the resolution when creating the Resolution
object. For example, you can set it to 150 DPI instead of 300 DPI:
Resolution resolution = new Resolution(150);
-
Process One Page at a Time: If you are processing multiple pages in a loop, try converting just one page first to see if the issue persists. This can help isolate whether the problem is with a specific page.
-
Update Aspose.PDF Library: Ensure that you are using the latest version of the Aspose.PDF library, as updates often include bug fixes and performance improvements.
-
Check for Resource Limitations: Monitor your system’s CPU and memory usage while running the conversion. If your system is running low on resources, it may cause the process to hang.
-
Error Handling: Implement error handling in your code to catch any exceptions that may occur during the conversion process. This can provide more insight into what might be going wrong.
Here is a modified version of your code that includes a reduced resolution and error handling:
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir + "fnac01.pdf");
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
try
{
using (FileStream imageStream = new FileStream(dataDir + "image" + pageCount + "_out" + ".png", FileMode.Create))
{
// Create PNG device with specified attributes
Resolution resolution = new Resolution(150); // Reduced resolution
PngDevice pngDevice = new PngDevice(resolution);
// Convert a particular page and save the image to stream
pngDevice.Process(pdfDocument.Pages[pageCount], imageStream);
}
}
catch (Exception ex)
{
Console.WriteLine($"Error processing page {pageCount}: {ex.Message}");
}
}
Console.WriteLine("PDF pages are converted to PNG successfully!");
If the issue persists after trying these suggestions, consider reaching out to Aspose support with details about the PDF file and the specific behavior you are encountering.
Sources:
[1]: ConvertAllPagesToPNG.cs
It Is a freeze, not an error…
Can we have real human support and no stupid AI response ? 
@tfipsrd
Thank you for writing to us.
The problem has been reproduced and I will create a task for the development team to fix it.
@tfipsrd
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-59163
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.