1

I have a requirement that I need to display checkbox on pdf document generated using itextsharp. However, as itextsharp doesn't support html input tag, the checkboxes did not appear on my page. I use asp.net checkboxlist control and I am thinking about adding background image to display the checkbox as checked or not checked, but for some reason, I could not get it to display still. Here is my code:

 Protected Sub Checkboxlist1_DataBound(sender As Object, e As EventArgs) Handles Checkboxlist1.DataBound
    If test <> "" Then
        Dim checklist As List(Of String) = ReturnListofStringClass.ReturnChecklistListOfString(test)

        For i = 0 To Checkboxlist1.Items.Count - 1
            For Each id As String In checklist
                If Checkboxlist1.Items(i).Value = id Then
                    Checkboxlist1.Items(i).Selected = True
                    Checkboxlist1.Items(i).Attributes("style") = "background: url(http://renegadeox.com/img/on.png) no-repeat red; height:300px; color: blue; font-size:20px;"
                End If
            Next
        Next
    End If
End Sub

The background color applied but not the image. Thanks for your help.

ryan
  • 75
  • 8
  • Anybody could shed some light on this please? Thanks – ryan Jul 21 '14 at 09:05
  • 1
    Are you using HTMLWorker? If so, CSS isn't supported, switch to XMLWorker. However I don't believe that [background images are supported in XMLWorker](http://demo.itextsupport.com/xmlworker/itextdoc/CSS-conformance-list.htm) yet either. Also, HTMLWorker doesn't handle form fields and I believe (but could be wrong) that XMLWorker still doesn't either. Do you need a checkbox that's interactive (clickable) or just an image? The latter should be easy, just put an actual `IMG` in there. For the former, you might have to [write your own tag processor](http://stackoverflow.com/a/24498296/231316) – Chris Haas Jul 21 '14 at 13:25
  • Chris, it's the later. I just need an image not interactive one. How can I put an image in there. Please refer to my above code. That's how I iterate through the checkboxlist. Thanks – ryan Jul 21 '14 at 21:05
  • An FYI, I use XMLWorker. – ryan Jul 21 '14 at 21:12
  • Chris, I found this link:http://stackoverflow.com/questions/14812955/how-to-add-image-background-to-pdf-for-every-page. Looks like background image is supported (perhaps not through CSS) but how I can add this in the place where the checkbox is supposed to be. Thanks – ryan Jul 21 '14 at 21:31

1 Answers1

1

Perhaps this will help.

Protected Sub Checkboxlist1_DataBound(sender As Object, e As EventArgs) Handles Checkboxlist1.DataBound
If test <> "" Then
    Dim checklist As List(Of String) = ReturnListofStringClass.ReturnChecklistListOfString(test)

    For i = 0 To Checkboxlist1.Items.Count - 1
        For Each id As String In checklist
            If Checkboxlist1.Items(i).Value = id Then
                Dim t AS string= Checkboxlist1.Items(i).Text
 Checkboxlist1.Items(i).Text = "<img src='http://renegadeox.com/img/on.png' style='width:10px; height:10px;' alt='' title='' />" & "  " & t

            End If
        Next
    Next
End If
End Sub

Cheers

loveprogramming
  • 538
  • 2
  • 5
  • 22