вставлять шрифт с помощью iTextSharp - PullRequest
1 голос
/ 22 марта 2012

У меня проблемы с встраиванием шрифта с помощью iTextSharp.В основном у меня есть PDF-документ в виде шаблона с несколькими текстовыми полями.Используются 3 шрифта, которые необходимо встроить: ITCCharterCom-Regular, ITCCharterCom-Italic и ITCCharterCom-BlackItalic.

Все в порядке, кроме шрифта ITCCharterCom-BlackItalic.Курсив и обычный курсив встроены, но не черный курсив.Кто-нибудь есть идеи о том, что я делаю неправильно?

Ниже приведен упрощенный фрагмент кода.

    Private Function saveBusinessCard() As String

    ' init
    Dim template As String = Server.MapPath("~/Resources/BC_Template.pdf")
    Dim pdfOutput As String = String.Format("~/Temp/{0}.pdf", HttpContext.Current.Session.SessionID.ToString())
    Dim output As String = Server.MapPath(pdfOutput)
    Dim reader As New PdfReader(template)
    Dim pdfOutputFile As FileStream = New FileStream(output, FileMode.Create)
    Dim stamper As New PdfStamper(reader, pdfOutputFile)
    Dim form As AcroFields = stamper.AcroFields

    ' font property name
    Dim textFontPropertyName = "textfont"

    ' font installation files
    Dim pathBlackItalic As String = HttpContext.Current.Server.MapPath("~\Resources\Fonts\ITCCharterCom-BlackItalic.ttf")
    Dim pathItalic As String = HttpContext.Current.Server.MapPath("~\Resources\Fonts\ITCCharterCom-Italic.ttf")
    Dim pathRegular As String = HttpContext.Current.Server.MapPath("~\Resources\Fonts\ITCCharterCom-Regular.ttf")

    ' create embedded fonts
    Dim blackItalic As BaseFont = BaseFont.CreateFont(pathBlackItalic,
                                                      BaseFont.IDENTITY_H,
                                                      BaseFont.EMBEDDED)
    Dim italic As BaseFont = BaseFont.CreateFont(pathItalic,
                                                 BaseFont.IDENTITY_H,
                                                 BaseFont.EMBEDDED)
    Dim regular As BaseFont = BaseFont.CreateFont(pathRegular,
                                                  BaseFont.IDENTITY_H,
                                                  BaseFont.EMBEDDED)

    ' assign fonts to text fields
    form.SetFieldProperty("txtContact", textFontPropertyName, italic, Nothing)
    form.SetFieldProperty("txtName", textFontPropertyName, blackItalic, Nothing)
    form.SetFieldProperty("txtTitle", textFontPropertyName, regular, Nothing)

    ' set pdf fields in document
    form.SetField("txtContact", "Contact here")
    form.SetField("txtName", "Name here")
    form.SetField("txtTitle", "Title here")

    ' make input fields plain text
    stamper.FormFlattening = True

    ' clean up
    stamper.Close()
    reader.Close()
    pdfOutputFile.Close()

    ' return output path
    Return pdfOutput

End Function

Спасибо, Том

...