简体   繁体   English

如何在解决方案中嵌入字体以用于带有RDLC的PDF

[英]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. 我有一个通过Webforms.LocalReport创建的RDLC报告,它使用我在开发机器上安装的一些自定义字体。 This works well, and embeds the fonts in the PDF so that others don't need the font installed to view. 这很好用,并将字体嵌入PDF中,以便其他人不需要安装字体来查看。

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? 我不想在每个'潜在'机器上安装字体 - 有没有办法将(.TTF)字体文件附加到(VB.NET)解决方案,并从这里拉出字体,而不是从本地机器?

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. 在您的情况下,您可以从文件>属性>字体选项卡中的开发机器生成的PDF文件中进行验证。 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. 如果属性值为EMBED_NOEMBEDDING,则该字体不会嵌入PDF文件中。 For more information, see "TTGetEmbeddingType" on msdn.microsoft.com. 有关更多信息,请参见msdn.microsoft.com上的“TTGetEmbeddingType”。

Secondly make sure that the font is installed on your web hosting server. 其次,请确保您的Web托管服务器上安装了该字体。

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. 如果是,则报表查看器PDF解析器会自动将字体嵌入到生成的每个PDF中,并且不需要将字体分发给每个用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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