简体   繁体   中英

How to embed a Font in solution to use for PDF with RDLC

I have an RDLC report created via Webforms.LocalReport that uses a few custom fonts that I have installed on my dev machine. This works well, and embeds the fonts in the PDF so that others don't need the font installed to view.

My problem is, when deploying to our production environment, there are a number of machines that may run the report. I don't want to have to install the font on each 'potential' machine - is there a way to attach the (.TTF) font file to the (VB.NET) solution, and have the font pulled from here, rather than from the local machine?

Hope this makes sense!!

If it helps, below is a sample of the code I'm using

    Dim PDFfile As FileInfo
    Dim deviceInfo As String = String.Empty
    Dim PDF() As Byte
    Dim reportParams As List(Of ReportParameter)

    Using report As New LocalReport

        ' Set up report
        ' Report device information to create PDF with A4 sized pages
        deviceInfo = "<DeviceInfo>" & _
                     "  <OutputFormat>EMF</OutputFormat>" & _
                     "  <Orientation>Portrait</Orientation>" & _
                     "  <PageWidth>21cm</PageWidth>" & _
                     "  <PageHeight>29.7cm</PageHeight>" & _
                     "  <MarginTop>0cm</MarginTop>" & _
                     "  <MarginLeft>0cm</MarginLeft>" & _
                     "  <MarginRight>0cm</MarginRight>" & _
                     "  <MarginBottom>0cm</MarginBottom>" & _
                     "</DeviceInfo>"
        With report
            .DisplayName = "Display Name"
            report.ReportEmbeddedResource = "ReportName.rdlc"

            ' Add all necessary parameters
            reportParams = New List(Of ReportParameter)
            reportParams.Add(...)

            .SetParameters(reportParams)
        End With

        PDF = report.Render("PDF", deviceInfo)
        PDFfile = New FileInfo("C:\")

        Using stream As FileStream = PDFfile.Create
            stream.Write(PDF, 0, PDF.Length)
        End Using
    End Using

Thanks in advance!

First of all make sure that the font you are using allows embedding. In your case you can verify it from the PDF file generated by your dev machine from File>Properties>Fonts tab. Font embedding privileges are granted by the font author. Installed fonts include a property that indicates whether the font author intends to allow embedding a font in a document. If the property value is EMBED_NOEMBEDDING, the font is not embedded in the PDF file. For more information, see "TTGetEmbeddingType" on msdn.microsoft.com.

Secondly make sure that the font is installed on your web hosting server.

If so then the report viewer PDF parser then automatically embeds the font to every PDF generated and there is no need for the font to be distributed to each user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM