Can not get image working in PDF creation



I am pretty new to this PDF software

I was trying to load an image and put some text besides it in a Table row.

I managed to get the text shown, but not the image

Can you take a quick look at the follow code, and let me know if I miss something (The Image URL, I test it in the IE, I can see it from browser so Image is there in my localhost)

Another notes, can you also give me a hint how to decide BitPerComponent and Component? I check my gif the only info I can get (right click on file–>properties) is BitPerPiexl=24. Did I set them right in the following code? Thanks

Attached code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim strLicFile As String
strLicFile = Server.MapPath(“bin”) & “/” & “Aspose.Pdf.lic”
Dim apdf As Pdf = New Pdf(strLicFile, Me)

apdf.Security = New Security
apdf.Security.IsCopyingAllowed = False

apdf.PageSetup.PageHeight = PageSize.LetterHeight
apdf.PageSetup.PageWidth = PageSize.LetterWidth

Dim aPageMargin As New MarginInfo
aPageMargin.Top = 20
aPageMargin.Left = 30
aPageMargin.Right = 30
aPageMargin.Bottom = 20
apdf.PageSetup.Margin = aPageMargin

Select Case Request.QueryString(“type”)
Case 1
Dim Headsection As Section = New Section(apdf)

'now we add the table
Dim HeadTable As New Aspose.Pdf.Table
Dim HeadRow As New Aspose.Pdf.Row(HeadTable)

Dim LogoCell As New Aspose.Pdf.Cell(HeadTable)
Dim HeadTextCell As New Aspose.Pdf.Cell(HeadTable)

Dim LogoImage As New Aspose.Pdf.Image(Headsection)
LogoImage.ImageInfo.File =“http://localhost/agpclite/images/mainlogo.jpg
LogoImage.ImageInfo.OpenType = ImageOpenType.Url
LogoImage.ImageWidth = 400
LogoImage.ImageHeight = 230
LogoImage.ImageInfo.BitsPerComponent = 8
LogoImage.ImageInfo.ComponentNumber = 3

Dim HeadText As New Text(Headsection)
Dim HeadTextSegment As New Segment(HeadText)
HeadTextSegment.Content = “my text”
'Dim text1 As Text = New Text(Headsection)
'text1.Margin.Top = 21

'Dim segment1 As Segment = New Segment(text1)
'segment1.Content = “Centrilift - a Baker Hughes Company”

'Dim segment2 As Segment = New Segment(text1)
'segment2.Content = “. We are currently working on this report. Coming soon.”
Case 2
Case 3
Case 4
End Select

End Sub


Dear zhudavh,

Thanks for your consideration.

Encryption for image from URL is not supported currently. You can remove the encryption setting or use image from local disk.


Thanks Tommy,

This is what I see in the API reference

image3.ImageInfo.File = “http://localhost/Images/SeaFood.jpg
image3.ImageInfo.ImageFileType = ImageFileType.Jpeg
image3.ImageInfo.OpenType = ImageOpenType.Url
image3.ImageInfo.Title = “jpeg image with url”
image3.ImageWidth = 154
image3.ImageHeight = 112
image3.ImageInfo.BitsPerComponent = 8
image3.ImageInfo.ComponentNumber = 3

If you take a look at my code. I did excetly same thing as the example. Except I was try to add the image to a table cell.

You mentioned "Encryption for image from URL ", if i took

image3.ImageInfo.BitsPerComponent = 8
image3.ImageInfo.ComponentNumber = 3
out from the code, i got an error message said:

The width,height,BitsPerComponent and ComponentNumber should be set in CCITT image.

I do not what to try next

1) can i add a image to a table cell?
2)what is image3.ImageInfo.BitsPerComponent = 8
image3.ImageInfo.ComponentNumber = 3
means? I wish I can send you the JPG file so you can tell me weather i set it right or wrong
3)I really want to do URL image open , local disk loading is not good for future server deployment

I have a deadline to develiev this report by next Monday. So your help will be greatly appreciated.




Dear David,

Thanks for your consideration.

1) Certainly you can add a image to a table cell;
2) When using image with URL, the image information is not really read from the image file, but some description infomation about the image is put into the PDF file. Here is an example in pdf file(open with text editor):

8 0 obj
/Width 154
/Height 112
/BitsPerComponent 8
/F<</FS/URL/F(http://localhost/Images/SeaFood.jpg)>>/Length 0>>

you can see the stream data of the image is empty. So you have to set the BitsPerComponent and ComponentNumber property. The ComponentNumber should be 1, 3, or 4 corresponding to
grayscale, RGB, or CMYK image. BitsPerComponent means the number of bits per component,it should be 1, 2, 4, or 8. BitsPerComponent must be 8 if type is jpeg, and 1 if type is ccitt.

3) I have removed the following code from you example and it can work:
apdf.Security = New Security
apdf.Security.IsCopyingAllowed = False