1

itextSharp を使用して、VB.Net および MSSQL 2005 で開発された Web アプリケーションで、html からランタイム pdf を作成する必要があります。

HTML はデータベースに保存されます。グジャラート語、ヒンディー語、英語のコンテンツが含まれています。

HTMLのフォントを設定する方法と、英語、グジャラート語、ヒンディー語を表示するフォントを使用する必要があることを誰か教えてもらえますか? Arial Unicode MSを試しましたが、ヒンディー語が正確に表示されません.

前もって感謝します

これは、html文字列をユーザーがローカルマシンに保存できるpdfファイルに変換するために使用しているメソッドのコードです。

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

これが私がコードを使用している方法です

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")   

グジャラート語の結果では、予想どおりઅનિલであるઅનલિが表示されています

ヒンディー語は अनलि と表示されていますが、 अनिल である必要があります。

4

2 に答える 2

0

残念ながら、あなたは運が悪いです。ここを参照してください。基本的に、iText開発者は、PDFでインド語を適切に表示するために必要な合字をサポートするために、コードの貢献を何度も呼びかけていますが、誰も支援を申し出ていません。

于 2012-03-05T17:41:17.263 に答える