Wie set-Schriftart in itextSharp für HTML-zu PDF

Habe ich zu laufen der Zeit pdf aus html in Web-Anwendung entwickelt, in VB.Net und MSSQL 2005, mit itextSharp.

Der HTML-Code wird gespeichert in der Datenbank. enthält Gujarati, Hindi und Englisch Inhalt.

Kann mir jemand sagen, wie die schriftart für die html-und welche schriftart soll ich verwenden, das display Enlgish, Gujarati und Hindi
Ich habe versucht, Arial Unicode MS, aber seine nicht angezeigt Hindi genau.

Danke im Voraus

hier ist der code der Methode, die ich verwende zum konvertieren von html-string in eine pdf-Datei, die Benutzer können speichern auf der lokalen Maschine.

Private Sub ExporttoPDF(ByVal FullHtml As String, ByVal fileName As String)
    Try
            Response.Clear()    ' Clear Response and set content type and disposition so that user get save file dialogue. 
            Response.ContentType = "application/pdf"
            Response.AddHeader("content-disposition", String.Format("attachment;filename={0}.pdf", fileName))
            Response.Cache.SetCacheability(HttpCacheability.NoCache)


            Dim sr As StringReader = New StringReader(FullHtml)
            Dim pdfDoc As iTextSharp.text.Document = New iTextSharp.text.Document(PageSize.A4.Rotate, 10, 10, 10, 10)
            Dim htmlparser As HTMLWorker = New HTMLWorker(pdfDoc)
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
            pdfDoc.Open()
            Dim fontpath As String = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\fonts\ARIALUNI.TTF" 
            '  "ARIALUNI.TTF" file copied from fonts folder and placed in the folder
            Dim bf As BaseFont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)

            FontFactory.RegisterDirectory( System.Web.HttpContext.Current.Request.PhysicalApplicationPath , True)

            FontFactory.Register(fontpath, "Arial Unicode MS")
            FontFactory.RegisterFamily("Arial Unicode MS", "Arial Unicode MS", fontpath)    

            'parse html from String reader "sr"
            htmlparser.Parse(sr)
            pdfDoc.Close()
            Response.Write(pdfDoc)
            Response.End()

    Catch ex As Exception
        Throw ex
    End Try
End Sub

Hier ist, wie ich bin mit dem code

dim htmlstring as string = "<html><body encoding=""" + BaseFont.IDENTITY_H + """ style=""font-family:Arial Unicode MS;font-size:12;""> <h2> set Font in itextSharp for HTML to PDF  </h2> <span> I (aneel/અનિલ/अनिल) am facing problem to create a pdf from html that contains enlish, ગુજરાતી, हिंदी and other unicode characters.  </span> </body></html>"         
ExporttoPDF(htmlstring ,"sample.pdf")   

In Folge
für Gujarati es zeigt અનલિ, wo wie erwartet ist અનિલ

Wo, wie für Hindi ist die Anzeige अनलि, wo wie es sein sollte अनिल .

ein soultution für dieses problem, indem Vinit_Patel von hier : stackoverflow.com/questions/21423993/...

InformationsquelleAutor Aneel Mehta | 2012-03-05

Schreibe einen Kommentar