问题
I try to render RDLC report to PDF file and the size of the file generated is larger than normal. After some research i found the PDF generated have embedded font: ..... 9 0 obj << /Filter /FlateDecode /Length 52986 /Length1 194264 >> stream .....
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.
The PDFs is identically if i open with Adobe Acrobat.
Solution 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.
Failed
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.
Failed
The small PDF font property:

The large PDF font property:

My question is: How to not embed default font in PDF rendered from RDLC?
回答1:
It turns out we merely needed to add a key to the DeviceInfo.xml:
<DeviceInfo>
<EmbedFonts>None</EmbedFonts>
</DeviceInfo>
I found the answer here.
回答2:
According to How to embed a Font in a PDF with RDLC you must meet these requirements:
- Font must be marked as embedding allowed
- Font must be of type TrueType
This is similar to the MSDN documentation on font embedding when exporting to a PDF File from Report Builder and SSRS:
- 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.- The Font is 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.
回答3:
You really shouldn't use Microsoft.ReportViewer.WebForms in ASP.NET MVC. 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
Font embedding was introduced:
SQL Server 2008 Cumulative Update 1 (full font embedding and subsetting for Unicode characters)
SQL Server 2005 Service Pack 3 (limited to non ANSI characters)
Reference: Do You Unicode in PDF?
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.
So when you disable fonts embedding you are basically reverting back to the old behavior.
How do disable:
- Open the RSreportserver.config file under the path: RS Installation Folder\Reporting Services\ReportServer
Reference: Modify a Reporting Services Configuration File (RSreportserver.config)
Find the following
<Extension Name="PDF" Type=" Microsoft.ReportingServices.Rendering.ImageRenderer.PdfReport, Microsoft.ReportingServices.ImageRendering"/>
Add the following
<Configuration> <DeviceInfo> <EmbedFonts>None</EmbedFonts> </DeviceInfo> </Configuration>
You would need to do an IISReset (IISReset stops and restarts the entire web server (including non-ASP.NET apps) to set the changes.
Reference: How to disable this Font embedding in Reporting Services 2005 Service Pack 3?
来源:https://stackoverflow.com/questions/22322774/exclude-default-font-embed-in-rdlc-render-to-pdf