简体   繁体   English

排除嵌入在RDLC渲染为PDF中的默认字体

[英]Exclude default font embed in RDLC render to PDF

I try to render RDLC report to PDF file and the size of the file generated is larger than normal. 我尝试将RDLC报告呈现为PDF文件,并且生成的文件大小比正常的大。 After some research i found the PDF generated have embedded font: ..... 9 0 obj << /Filter /FlateDecode /Length 52986 /Length1 194264 >> stream ..... 经过一番研究,我发现生成的PDF嵌入了字体:..... 9 0 obj << / Filter / FlateDecode / Length 52986 / Length1 194264 >>流.....

When i generate PDFs and save to disk with the same method and the same code one PDF have the size: 6.82 KB and other 109 KB. 当我生成PDF并使用相同的方法和相同的代码保存到磁盘时,一个PDF的大小为:6.82 KB和其他109 KB。

The PDFs is identically if i open with Adobe Acrobat. 如果我使用Adobe Acrobat打开,则PDF完全相同。

Solution 1: 解决方案1:

I generate the PDF in MVC 4 application with "Microsoft.ReportViewer.WebForms" version 11. I try to use "Microsoft.ReportViewer.WinForms" library in the same MVC application to see if the size decreases but no result. 我在具有“ Microsoft.ReportViewer.WebForms”版本11的MVC 4应用程序中生成PDF。我尝试在同一MVC应用程序中使用“ Microsoft.ReportViewer.WinForms”库,以查看大小是否减小但没有结果。

Failed 失败

Solutin 2: Solutin 2:

I search in RDLC file with notepad if exist something about fonts but not exist, only font size, if is bold but not some name. 我使用记事本在RDLC文件中进行搜索,如果存在有关字体的某些内容但不存在,则仅存在字体大小(如果为粗体但没有某些名称)。

Failed 失败

The small PDF font property: 小PDF字体属性: 小PDF

The large PDF font property: 大的PDF字体属性: 在此处输入图片说明

My question is: How to not embed default font in PDF rendered from RDLC? 我的问题是:如何不在从RDLC渲染的PDF中嵌入默认字体?

It turns out we merely needed to add a key to the DeviceInfo.xml: 事实证明,我们只需要向DeviceInfo.xml添加密钥:

<DeviceInfo>
<EmbedFonts>None</EmbedFonts>
</DeviceInfo>

I found the answer here . 在这里找到了答案

According to How to embed a Font in a PDF with RDLC you must meet these requirements: 根据如何使用RDLC在PDF中嵌入字体,您必须满足以下要求:

  • Font must be marked as embedding allowed 字体必须标记为允许嵌入
  • Font must be of type TrueType 字体必须为TrueType类型

This is similar to the MSDN documentation on font embedding when exporting to a PDF File from Report Builder and SSRS: 这类似于从Report Builder和SSRS导出为PDF文件时有关字体嵌入的MSDN文档

  • 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”。
  • The Font is TrueType. 字体是TrueType。
  • Fonts are referenced by visible items in a report. 字体由报表中的可见项目引用。 If a font is referenced by an item that has the Hidden property set to True, the 如果某个字体被“隐藏”属性设置为“真”的项目引用,则
    font is not needed to display rendered data and will not be included 字体不需要显示渲染数据,也不会包含在内
    in the file. 在文件中。 Fonts are embedded only when they are needed to display 字体仅在需要显示时才嵌入
    the rendered report data. 呈现的报告数据。

So if you do not meet these requirements, your font should not be embedded. 因此,如果您不满足这些要求,则不应嵌入您的字体。

You really shouldn't use Microsoft.ReportViewer.WebForms in ASP.NET MVC. 您实际上不应该在ASP.NET MVC中使用Microsoft.ReportViewer.WebForms Rather just call your report server and get the report needed. 而是只需致电您的报表服务器并获取所需的报表即可。

public async Task<FileStreamResult> GenerateReport()
{

    CredentialCache credentialCache = new CredentialCache();
    credentialCache.Add(new Uri("http://domainORipaddress"), "NTLM", new NetworkCredential(
        ConfigurationManager.AppSettings["username"],
        ConfigurationManager.AppSettings["password"]
    ));

    Stream report = null;
    using (var httpClient = new HttpClient(new HttpClientHandler { Credentials = credentialCache }))
    { 
        //put the desired timeout here if needed to cancel the task
        httpClient.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
        report = await httpClient.GetStreamAsync("reportUrl");
    }

    Response.AppendHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", reportName));
    return File(reportPath, MediaTypeNames.Application.Pdf);
}

Reference: SQL Server Reporting Service with ASP.NET MVC 参考: 具有ASP.NET MVC的SQL Server报告服务

Font embedding was introduced: 字体嵌入介绍:

SQL Server 2008 Cumulative Update 1 (full font embedding and subsetting for Unicode characters) SQL Server 2008累积更新1 (完整字体嵌入和Unicode字符子集)

SQL Server 2005 Service Pack 3 (limited to non ANSI characters) SQL Server 2005 Service Pack 3 (限于非ANSI字符)

Reference: Do You Unicode in PDF? 参考: 您是否在PDF中使用Unicode?

Font embedding does no longer matter what version of a font is installed on a client - the documents can be viewed the same way regardless of client operating systems, font versions, and client PDF viewer. 字体嵌入不再取决于客户端上安装的字体是什么版本-可以以相同方式查看文档,而不管客户端操作系统,字体版本和客户端PDF查看器如何。

So when you disable fonts embedding you are basically reverting back to the old behavior . 因此,当禁用字体嵌入时,您基本上会恢复到旧的行为

How do disable: 如何禁用:

  1. Open the RSreportserver.config file under the path: RS Installation Folder\\Reporting Services\\ReportServer 打开以下路径下的RSreportserver.config文件: RS Installation Folder \\ Reporting Services \\ ReportServer

Reference: Modify a Reporting Services Configuration File (RSreportserver.config) 参考: 修改Reporting Services配置文件(RSreportserver.config)

  1. Find the following 找到以下内容

      <Extension Name="PDF" Type=" Microsoft.ReportingServices.Rendering.ImageRenderer.PdfReport, Microsoft.ReportingServices.ImageRendering"/> 
  2. Add the following 添加以下内容

      <Configuration> <DeviceInfo> <EmbedFonts>None</EmbedFonts> </DeviceInfo> </Configuration> 
  3. You would need to do an IISReset (IISReset stops and restarts the entire web server (including non-ASP.NET apps) to set the changes. 您将需要执行IISReset (IISReset停止并重新启动整个Web服务器(包括非ASP.NET应用程序)以设置更改。

Reference: How to disable this Font embedding in Reporting Services 2005 Service Pack 3? 参考: 如何在Reporting Services 2005 Service Pack 3中禁用此字体嵌入?

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

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