Thursday, 20 July 2017

Crystal report ExportToDisk as PDF loses barcode font

I've been working on a .Net MVC Web API, part of which takes some data and produces a PDF using ExportToDisk provided by CrystalDecisions.CrystalReports.Engine.dll.

This proved to be relatively easy, as did the inclusion of a barcode font in the report, along with some vb code in a forumula field, that cleverly takes a supplied number and renders it as a barcode.

A problem arose when exporting a report containing this barcode to PDF - the barcode was not visible in the PDF. This seems to be a common problem with what feels like a rather hacky fix - adding a registry key. This is how it's done:

Open up registry editor (regedit) and navigate to HKEY_CURRENT_USER\Software\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Crystal Reports\Export. Add a new key called PDF, and a new value to it of Type 'DWORD' and name 'ForceLargerFonts' and value '1'. It should look like this when you've done: