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

Free Support Forum - aspose.com

Problem inserting file into pdf

Hi Support,
I am generating a PDF with a table of conference speakers. In this table I display the speaker's image and names. Most of the time it works great. However some times if an image is used more than once I get the error message below on the create file stream line.

The process cannot access the file 'C:\accountimages\no_person.jpg' because it is being used by another process.

My code is below. Should I be releasing, disposing, or setting img or img.imagestream to Nothing? How do I make it so a repeat file can occur. I have no way of knowing in advance which images may repeat.

Dim Row As Aspose.Pdf.Row = table.Rows.Add()

Dim img As Aspose.Pdf.Image = New Aspose.Pdf.Image
img.ImageStream = New FileStream(strPhysicalPath, FileMode.Open)

Row.Cells(0).Paragraphs.Add(img)

Dim t As Aspose.Pdf.HtmlFragment = New Aspose.Pdf.HtmlFragment("my html text"
Row.Cells(1).Paragraphs.Add(t)

Please help!

Thanks,
Mike


FIXED.


This turns out to not have been an Aspose issue. I needed to open the file stream as “shared” as follows:

img.ImageStream = New FileStream(strPhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read)

Thanks anyway!

Hi Mike,


Thanks for contacting support.

When referencing/loading an Image into Stream object, you need to ensure that after the image has been used, you release the object holding image or load image in read only mode. Else it may not be accessible in further routines.

Nevertheless, we are glad to hear that your problem is resolved. Please continue using our API and in the event of any further query, please feel free to contact.

We apologize for the inconvenience caused.