Wkhtmltopdf will not make images inside html files

We use wkhtmltopdf (in the wkhtmltoxsharp lib), taking local .html files and converting them to .pdf files.

Inside HTML, we have a web link to a network drive with a .gif image. when converting .pdf leaves without an image.

Any thoughts on how to achieve this?

Learn more about this in Google Code .

+3
source share
4 answers

The windows version wkhtmltopdf 0.11.0 rc1 does not support gif images. Workaround: pre-process all the images in the incoming HTML and convert them to jpg.

The issue is described in: http://code.google.com/p/wkhtmltopdf/issues/detail?id=441

Gifs work in wkhtmltopdf 0.9.9.

+5

, , , - : 1.1.4 0.10, GIF, JPG ..

, , ( http://localhost/) , , .

: <img src="../somepath/echoimage.php?params" >

, , , , .

src, , : <img src="http://localhost/fullpath/echoimage.php?params" >

, , , / . , .

+6

Just use the code below, which will change your html src from mapped to absolute path and you will get an image. wkhtmltopdf accepts jpeg and gif both image types

  Public Function getImage(ByVal input As String) As String
    If input Is Nothing Then
        Return String.Empty
    End If
    Dim tempInput As String = input
    Dim pattern As String = "<IMG(.|)+?>"
    Dim src As String = String.Empty
    Dim context As HttpContext = HttpContext.Current
    'Change the relative URL to absolute URL for an image, if any in the HTML code. 
    For Each m As Match In Regex.Matches(input, pattern, RegexOptions.IgnoreCase Or RegexOptions.Multiline Or RegexOptions.RightToLeft)
        If m.Success Then
            Dim tempM As String = m.Value
            Dim pattern1 As String = "src=['|""](.+?)['|""]"
            Dim reImg As New Regex(pattern1, RegexOptions.IgnoreCase Or RegexOptions.Multiline)
            Dim mImg As Match = reImg.Match(m.Value)
            If mImg.Success Then
                src = mImg.Value.ToLower().Replace("src=", "").Replace("""", "")
                If src.ToLower().Contains("http://") = False Then
                    'IIf you want to access through you can use commented src line below 
                    '   src = "src=\"" + context.Request.Url.Scheme + "://" + context.Request.Url.Authority + "/" + src + "\"";
                    src = "src=""" & Server.MapPath("~") & "\" & src & """"


                    Try
                        tempM = tempM.Remove(mImg.Index, mImg.Length)
                        tempM = tempM.Insert(mImg.Index, src)
                        'insert new url img tag in whole html code 
                        tempInput = tempInput.Remove(m.Index, m.Length)
                        tempInput = tempInput.Insert(m.Index, tempM)
                    Catch e As Exception
                    End Try
                End If
            End If
        End If
    Next
    Return tempInput
End Function
+1
source

If you defined the image code in css, delete that code and you will get a PDF with images.

0
source

All Articles