Issue with save - loop forever ? VB

Hello,

I have an issue with the way the PDF is saved.
When we made an error in the code with the images or the table structure for examples, sometimes it doesn’t throw an exception during the processing and it keeps going till it goes to the save and then it just stays here, running, never stopping.
It causes our program an important issue because it keeps running even if it is on error. Is there a way for you to throw an exception instead of keep saving indefinitely ? Cause we have a lot of PDF exports that just never stop and we need to have the full capacity of our servers.

Here’s an example of code that doesn’t work without stopping.
Dim license As License = New License
license.SetLicense(“Aspose.Total.lic”)
Dim Doc = New Pdf

’ add the section to PDF document sections collection
Dim section As Aspose.Pdf.Section = New Section(Doc)
Doc.Sections.Add(section)

Dim Tableau As Table = New Table()
Tableau.ColumnWidths = "300"

Dim Row As Row = Tableau.Rows.Add()
Dim Cellule As Cell = Row.Cells.Add()

Dim flux As New System.IO.MemoryStream
Dim b As System.Drawing.Bitmap = New System.Drawing.Bitmap(“D:/imgentete.png”)
b.Save(flux, System.Drawing.Imaging.ImageFormat.Png)
Dim image As Aspose.Pdf.Image = New Aspose.Pdf.Image()
image.ImageInfo.ImageFileType = ImageFileType.Jpeg
image.ImageInfo.Alignment = AlignmentType.Center
image.ImageInfo.ImageStream = flux

image.ImageInfo.FixWidth = 262
Cellule.Paragraphs.Add(image)
Cellule.VerticalAlignment = VerticalAlignmentType.Bottom

section.Paragraphs.Add(Tableau)

Console.Write(“before save”)
Doc.Save(“D:/TestImage.pdf”)
Console.Write(“after save”)

Hello Anouck,

Thanks for using our products and sorry for replying you late.

I have tested the scenario and as per my observations, an error message is being displayed over code line image.ImageInfo.ImageFileType = ImageFileType.Jpeg because in code above this line, you are trying to open a PNG format image and specifying the image type as JPEG. In order to properly generate the PDF, please update the image type to Png.

I have tested the scenario in a Windows Desktop application and I am unable to notice any problem. I have tested the scenario using Aspose.Pdf for .NET 5.0.0. Can you please share some more details regarding your working environment. We apologize for your inconvenience.

I know that I have this error with the images as I made it to show you the issue with the save.
I am working with the 4.5.0.0 version of Aspose.Pdf and I can’t update this one for the moment (need some authorizations). But maybe if you can guarantee that this error with the “save” will not occurred anymore after I change the version, I’ll be able to purpose it to the right people.

Thanks for the help !

Hello Anouck,

Thanks for sharing the details.

I have tested the scenario with Aspose.Pdf for .NET 4.5.0 and as per my observations, when improper image file type is specified, program keeps on running and never ends. However, during my testing with Aspose.Pdf for .NET 5.0.0, the program comes to an end with proper error message "Can't open image file". Before you proceed with license upgrade, I would recommend you to please try using the latest product version in evaluation mode and once you are certain about this product release, then you may proceed with license purchase. You can download the latest product version from this link.

In case you have any further query, please feel free to contact. We apologize for your inconvenience.