Images causing table to be created too low on page

I am attempting to create a table with an image in each cell. There is a potential that I may use any of 30 different images in the table. The problem is that for every image I add to the section paragraph the beginning of the table drops down on the page the size of the image. Attached is a sample of what is happening and a sample of what should be created when my application is finished. Below is the code that I’m using to generate the PDF.

sideArray = ((72,0),(60,1),(48,0),(42,0),(36,0),(24,1))
topArray = ((72,1),(60,1),(48,0),(42,0),(36,0),(24,1))
imageWidthPassed = 168

Protected Sub createAblyMap(ByVal sideArray As Array, ByVal topArray As Array, ByVal imageWidthPassed As Decimal)
Dim image6ftR, image5ftR, image4ftR, image3halfftR, image3ftR, image2ftR As Aspose.Pdf.Image
Dim imageCTL, imageCTR As Aspose.Pdf.Image
Dim sizeWidth As Decimal
Dim colCounter As Integer = -1
Dim rowCounter As Integer = -1
Dim imageLocation As String = “D:/wwwroot/StageScreen/images/”
Dim pdfFileName As String

sizeWidth = 800 / ((((roundUp(imageWidthPassed / 12 / 0.5) / 2) - 1) * 12) + 28.5 + 3)

Dim pdf1 As Pdf = New Pdf()
'Enable the Landscape property
pdf1.IsLandscape = True
'Set the properties of Pdf instance
pdf1.Author = “Draper, Inc.”
pdf1.Creator = “Aspose.Pdf”
pdf1.Keywords = “Draper StageScreen Instructions”
pdf1.Subject = “Draper StageScreen Instructions”
pdf1.Title = “Draper StageScreen Instructions”

Dim sec1 As Aspose.Pdf.Section = pdf1.Sections.Add()
sec1.PageInfo.Margin.Left = 20
sec1.PageInfo.Margin.Right = 20
sec1.PageInfo.Margin.Top = 20
sec1.PageInfo.Margin.Bottom = 20

imageCTL = New Aspose.Pdf.Image(sec1)
sec1.Paragraphs.Add(imageCTL)
imageCTL.ImageInfo.File = imageLocation & “Corner-TL.jpg”
imageCTL.ImageInfo.ImageFileType = ImageFileType.Jpeg
imageCTL.ImageInfo.FixWidth = 16 * sizeWidth
imageCTR = New Aspose.Pdf.Image(sec1)
sec1.Paragraphs.Add(imageCTR)
imageCTR.ImageInfo.File = imageLocation & “Corner-TR.jpg”
imageCTR.ImageInfo.ImageFileType = ImageFileType.Jpeg
imageCTR.ImageInfo.FixWidth = 16 * sizeWidth

image6ftR = New Aspose.Pdf.Image(sec1)
sec1.Paragraphs.Add(image6ftR)
image6ftR.ImageInfo.File = imageLocation & “6ftTop.jpg”
image6ftR.ImageInfo.ImageFileType = ImageFileType.Jpeg
image6ftR.ImageInfo.FixWidth = 72 * sizeWidth
image5ftR = New Aspose.Pdf.Image(sec1)
sec1.Paragraphs.Add(image5ftR)
image5ftR.ImageInfo.File = imageLocation & “5ftTop.jpg”
image5ftR.ImageInfo.ImageFileType = ImageFileType.Jpeg
image5ftR.ImageInfo.FixWidth = 60 * sizeWidth
image4ftR = New Aspose.Pdf.Image(sec1)
sec1.Paragraphs.Add(image4ftR)
image4ftR.ImageInfo.File = imageLocation & “4ftTop.jpg”
image4ftR.ImageInfo.ImageFileType = ImageFileType.Jpeg
image4ftR.ImageInfo.FixWidth = 48 * sizeWidth
image3halfftR = New Aspose.Pdf.Image(sec1)
sec1.Paragraphs.Add(image3halfftR)
image3halfftR.ImageInfo.File = imageLocation & “3halfftTop.jpg”
image3halfftR.ImageInfo.ImageFileType = ImageFileType.Jpeg
image3halfftR.ImageInfo.FixWidth = 42 * sizeWidth
image3ftR = New Aspose.Pdf.Image(sec1)
sec1.Paragraphs.Add(image3ftR)
image3ftR.ImageInfo.File = imageLocation & “3ftTop.jpg”
image3ftR.ImageInfo.ImageFileType = ImageFileType.Jpeg
image3ftR.ImageInfo.FixWidth = 36 * sizeWidth
image2ftR = New Aspose.Pdf.Image(sec1)
sec1.Paragraphs.Add(image2ftR)
image2ftR.ImageInfo.File = imageLocation & “2ftTop.jpg”
image2ftR.ImageInfo.ImageFileType = ImageFileType.Jpeg
image2ftR.ImageInfo.FixWidth = 24 * sizeWidth

Dim outerTable As Table = New Table
sec1.Paragraphs.Add(outerTable)
sec1.PageInfo.PageWidth = PageSize.A4Width
sec1.PageInfo.PageHeight = PageSize.A4Height
outerTable.ColumnWidths = “800”
outerTable.DefaultCellBorder = New BorderInfo(BorderSide.All, 0.1F)
Dim outerRow As Row = outerTable.Rows.Add()

Dim tab1 As Table = New Table
'tab1.DefaultCellBorder = New BorderInfo(BorderSide.All, 0.1F)
Dim colWidths As String = “4”
For i = 0 To 200
colWidths = colWidths & " 4"
Next

tab1.ColumnWidths = colWidths
outerRow.Cells.Add().Paragraphs.Add(tab1)

'Create rows in the table and then cells in the rows
rowCounter = rowCounter + 1
tab1.Rows.Add()
colCounter = colCounter + 1
tab1.Rows(rowCounter).Cells.Add().Paragraphs.Add(imageCTL)
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 4 * sizeWidth
If topArray(0, 1) > 0 Then
tab1.Rows(rowCounter).Cells.Add().Paragraphs.Add(image6ftR)
topArray(0, 1) = topArray(0, 1) - 1
colCounter = colCounter + 1
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 18 * sizeWidth '72/4 = 18
Do While topArray(0, 1) > 0
tab1.Rows(rowCounter).Cells.Add(tab1.Rows(rowCounter).Cells(colCounter).CompleteClone())
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 18 * sizeWidth
topArray(0, 1) = topArray(0, 1) - 1
colCounter = colCounter + 1
Loop
End If
If topArray(1, 1) > 0 Then
tab1.Rows(rowCounter).Cells.Add().Paragraphs.Add(image5ftR)
topArray(1, 1) = topArray(1, 1) - 1
colCounter = colCounter + 1
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 15 * sizeWidth '60/4=15
Do While topArray(1, 1) > 0
tab1.Rows(rowCounter).Cells.Add(tab1.Rows(rowCounter).Cells(colCounter).CompleteClone())
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 15 * sizeWidth
topArray(1, 1) = topArray(1, 1) - 1
colCounter = colCounter + 1
Loop
End If
If topArray(2, 1) > 0 Then
tab1.Rows(rowCounter).Cells.Add().Paragraphs.Add(image4ftR)
topArray(2, 1) = topArray(2, 1) - 1
colCounter = colCounter + 1
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 12 * sizeWidth '48/4=12
Do While topArray(2, 1) > 0
tab1.Rows(rowCounter).Cells.Add(tab1.Rows(rowCounter).Cells(colCounter).CompleteClone())
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 12 * sizeWidth
topArray(2, 1) = topArray(2, 1) - 1
colCounter = colCounter + 1
Loop
End If
If topArray(3, 1) > 0 Then
tab1.Rows(rowCounter).Cells.Add().Paragraphs.Add(image3halfftR)
topArray(3, 1) = topArray(3, 1) - 1
colCounter = colCounter + 1
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 10.5 * sizeWidth '42/4=10.5
Do While topArray(3, 1) > 0
tab1.Rows(rowCounter).Cells.Add(tab1.Rows(rowCounter).Cells(colCounter).CompleteClone())
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 10.5 * sizeWidth
topArray(3, 1) = topArray(3, 1) - 1
colCounter = colCounter + 1
Loop
End If
If topArray(4, 1) > 0 Then
tab1.Rows(rowCounter).Cells.Add().Paragraphs.Add(image3ftR)
topArray(4, 1) = topArray(4, 1) - 1
colCounter = colCounter + 1
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 9 * sizeWidth '36/4=9
Do While topArray(4, 1) > 0
tab1.Rows(rowCounter).Cells.Add(tab1.Rows(rowCounter).Cells(colCounter).CompleteClone())
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 9 * sizeWidth
topArray(4, 1) = topArray(4, 1) - 1
colCounter = colCounter + 1
Loop
End If
If topArray(5, 1) > 0 Then
tab1.Rows(rowCounter).Cells.Add().Paragraphs.Add(image2ftR)
topArray(5, 1) = topArray(5, 1) - 1
colCounter = colCounter + 1
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 6 * sizeWidth '24/4=6
Do While topArray(5, 1) > 0
tab1.Rows(rowCounter).Cells.Add(tab1.Rows(rowCounter).Cells(colCounter).CompleteClone())
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 6 * sizeWidth
topArray(5, 1) = topArray(5, 1) - 1
colCounter = colCounter + 1
Loop
End If
colCounter = colCounter + 1
tab1.Rows(rowCounter).Cells.Add().Paragraphs.Add(imageCTR)
tab1.Rows(rowCounter).Cells(colCounter).ColumnsSpan = 4 * sizeWidth

pdfFileName = DateTime.Now.ToString & “.pdf”

'pdf1.Save(“mypdf.pdf”, SaveType.OpenInAcrobat, Response)
pdf1.Save(pdfFileName, SaveType.OpenInAcrobat, Response)

End Sub

Hello Vince,

Sorry for replying you late.
In fact I’ve been busy while testing issue, but I’m afraid I couldn’t complete my test due to missing image resource files. While looking over the sample PDF that you’ve shared, I’ve been able to create some image files, but I’m afraid I’m not sure about the images that you have referred as 3ftTop.jpg and 4ftTop.jpg. It would really help us while investigating the issue, if you could share all the resource files that are used in the sample code.
We apologize for your inconvenience

I was not sure that you would need my image files. I thought that any jpeg might cause the same problem. Attached is a zip file of the images that I am using to this point. There will eventually be a different image for each side of the square.

Thank you,
Vince.

Hello Vince,

Thanks for sharing the image resources.

Yes, you are correct. The issue that you initially reported can be seen while using any image file, but I requested the image files because I wanted to be sure about the issue before I commented on it.

After thorough investigation, it has been observed that according to your statement that “the table drops down on the page the size of the image” is occurring because you are adding the same image object in the Paragraphs collection of the PDF document and again using the same image to be added in the table cells. As the image object is the same, so for the first time when you add the image in the paragraphs collection of the Section object, an empty space equal to the image size is being added.

For the sake of correction, try using the Image.CompleteClone() method when adding the image to the paragraphs collection of the section.

i.e.

imageCTL = New Aspose.Pdf.Image(sec1)
imageCTL.ImageInfo.File = imageLocation & "Corner-TL.jpg
imageCTL.ImageInfo.ImageFileType = ImageFileType.Jpeg
imageCTL.ImageInfo.FixWidth = 16 * sizeWidth
sec1.Paragraphs.Add(imageCTL.CompleteClone())

The resultant PDF that I’ve generated with this test is in the attachment. Please take a look.

Now I understand. I was doing too much work. Thanks for the clarification. It’s working great now.