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

Free Support Forum - aspose.com

Reusing Image as Cell Background

I am using an image as a background for a cell so I can overlay text on the image. I use the same image as the background form multiple cells, and I get the following exception when calling Save():


The process cannot access the file ‘[Image File Name]’ because it is being used by another process.

I don’t get the exception if I comment out the second usage of the file.

I created a simple sample to demonstrate the issue:

var document = new Document();
var page = document.Pages.Add();
var table = new Table();
var yPosition = 50;
table.Left = 50;
table.Top = yPosition;
table.ColumnWidths = “387”;
var row = table.Rows.Add();
row.FixedRowHeight = 18;
var cell = row.Cells.Add();
cell.BackgroundImageFile = myDir + “[Image File Name]”;
var textFragment = new TextFragment(“HeaderText”);
textFragment.TextState.FontSize = 10;
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.White);
textFragment.TextState.LineSpacing = .1f;
cell.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Bottom;
cell.Paragraphs.Add(textFragment);
page.Paragraphs.Add(table);
yPosition += 50;
table = new Table();
table.Left = 50;
table.Top = yPosition;
table.ColumnWidths = “387”;
row = table.Rows.Add();
row.FixedRowHeight = 18;
cell = row.Cells.Add();
cell.BackgroundImageFile = myDir + “[Image File Name]”;
textFragment = new TextFragment(“HeaderText”);
textFragment.TextState.FontSize = 10;
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.White);
textFragment.TextState.LineSpacing = .1f;
cell.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Bottom;
cell.Paragraphs.Add(textFragment);
page.Paragraphs.Add(table);
document.Save(myDir + “document.pdf”);

I need the ability to use the same file for several cell backgrounds so I can overlay text. What is the best way to accomplish this if I can’t use the above method.

Thanks.

Hi there,


Sorry for the inconvenience faced. After initial investigation, I’ve logged an investigation ticket as PDFNEWNET-35321 for further investigation in our issue tracking system. We are looking into issue and will notify you via this forum thread as soon as it is resolved.

Best Regards,

I am having the same problem when my multi-thread application and the exception

C:\Temp\Aspose\Images\Interpreter_Service.pngC:\Temp\Aspose\Images\Interpreter_Service.png because it is being used by another process.because it is being used by another process.

Please let me know you have a fix.

Danny

Aspose.Pdf.Row row = new Row();
row.Cells.Add(new Aspose.Pdf.Cell());
Aspose.Pdf.Cell cell = new Aspose.Pdf.Cell();
if (infor.Type == InformationType.HeaderText)
{
cell.Paragraphs.Add(Utility.CreateText(infor.InforText, foregroundColor, Aspose.Pdf.HorizontalAlignment.Left, fontSizeHeader, fontFranchise));
}
else if (infor.Type == InformationType.GeneralText)
{
cell.Paragraphs.Add(Utility.CreateText(infor.InforText, foregroundColor, Aspose.Pdf.HorizontalAlignment.Left, fontSize, font));
}
else if (infor.Type == InformationType.Image)
{

row.FixedRowHeight = 47.0f;
Aspose.Pdf.Image img = new Aspose.Pdf.Image();
img.FixHeight = 47.0f;
img.File = @"C:\Temp\Aspose\Images\Interpreter_Service.png";
cell.Paragraphs.Add(img);
}

row.Cells.Add(cell);
table.Rows.Add(row); Aspose.Pdf.Row row = new Row();
row.Cells.Add(new Aspose.Pdf.Cell());
Aspose.Pdf.Cell cell = new Aspose.Pdf.Cell();
if (infor.Type == InformationType.HeaderText)
{
cell.Paragraphs.Add(Utility.CreateText(infor.InforText, foregroundColor, Aspose.Pdf.HorizontalAlignment.Left, fontSizeHeader, fontFranchise));
}
else if (infor.Type == InformationType.GeneralText)
{
cell.Paragraphs.Add(Utility.CreateText(infor.InforText, foregroundColor, Aspose.Pdf.HorizontalAlignment.Left, fontSize, font));
}
else if (infor.Type == InformationType.Image)
{

row.FixedRowHeight = 47.0f;
Aspose.Pdf.Image img = new Aspose.Pdf.Image();
img.FixHeight = 47.0f;
img.File = @"C:\Temp\Aspose\Images\Interpreter_Service.png";
cell.Paragraphs.Add(img);
}

row.Cells.Add(cell);
table.Rows.Add(row); v

Hi Danny,


Thanks for your inquiry. Please note above reported issue has already been fixed in Aspose.Pdf for .NET 8.1.0 version. Please download and try latest version of Aspose.Pdf for .NET, hopefully it will fi the issue. If issue persist then please share a console application/working code to replicate the issue, as we are unable to test your code due to missing references.

Moreover, please note Aspose APIs do support Multithreading and you may create multi-threaded applications using these APIs. But, these are multi-thread safe as long as only one thread works on a document at a time. If you manipulate a single document in different threads, the results would be unstable.

We are sorry for the inconvenience caused.

Thank you.