Chapter 8. Adding PDF417 Symbols to SQL Server Reporting Service

Adding PDF417 symbols to SQL Reporting Service is straightforward with PDF417 Fonts & Encoder 5. This chapter explains how you can achieive the objective. Our report service plugin supports SQL Reporting Service 2008 and above. The example in this chapter uses Visual Studio 2010/SQL Reporting Service 2012 for demonstration. If you want to follow the tutorial steps by step, the AdventureWorks2012 sample database is required to be installed. You can find the sample database by searching Internet.

8.1. Custom Assembly

SSRS can't use the encoder DLL directly. A ready-to-use custom assembly (ReportServicePlugin_PDF417.dll) built under Visual Studio 2010 (.net 2.0) is included in the software.

Note

In case that you need to build the assembly by yourself, The source code is also included in the distribution. The project files are packed in ReportServicePlugin_src.zip, which is located under the program (x86) folder. The build script is written in NAnt.

This assembly exposes two functions: PDF417Encode and PDF417CompactEncode. The prototype for this function is as below:

string PDF417Encode(string strDataToEncode, 
    int numRows, int numCols,
    int securityLevel, 
    double aspectRatio,
    double yHeight); 
    
string PDF417CompactEncode(string strDataToEncode, 
    int numRows, int numCols,
    int securityLevel, 
    double aspectRatio,
    double yHeight); 

The two functions have the same signature. The only difference is that the first function produces barcode strings for full size PDF417 barcodes, and the other compact PDF417 barcodes. or the meanings of the parameter, refer to Section 5.3, “PDF417Encode2”. Note that the yHeight parameter should match the font used in order to calculate the aspect ratio correctly, unless you are not using this parameter. To learn how parameters affect the symbol size, see Section 2.3, “Sizing Parameters”.

8.1.1. Installing Custom Assembly

Copy the DLL into the following directories:

  • Report Designer Folder: [Program Files]Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies.

  • Deploy folder [Program Files]Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin.

If you have multiple SQL Server instances, you will have multiple MSSQL.n directories. Locate the one that the Reporting Service is installed under.

If you are running Visual Studio 2008 and above, you also need to modify RSPreviewPolicy.config in order to preview the report. See the section "Deployment" for details on the step.

8.2. Adding PDF417 Barcodes to Report

  1. Open Visual Studio or SQL Server Business Intelligence Development Studio and create a new Report Server Project.

  2. In Query builder, enter SQL statement SELECT Name, ProductNumber, ListPrice FROM Production.Product.

  3. Layout the report as desired. Make changes to the format of each field. Add a new column to the right that will hold the barcodes. The result looks like below:

  4. Select ReportReport Properties to bring up Report Properties dialog.

  5. click on References tab. Navigate to the location of the customer assembly and add it.

  6. Click on the new column created, and select expressions, change its value to the formula below:

    =Morovia.ReportService.PDF417V5.PDF417Encode(Fields!ProductNumber.Value, 0, 3, 0, 0, 3.0)

    The formula calls the PDF417Encode function with automatic error correction level 3 columns and target aspect ratio 3.0.

  7. Now preview the report. You should see lines of hexadecimal characters at the place of the barcode.

  8. Format the text box with MRV PDF417 N3, 6 points. Preview the report again, you should see the barcodes.

If you are printing to a laser printer, you should get a good quality barcode label printed. Now if you are printing to a low resolution thermal printer, such as a Zebra with 203 dpi in resolution, you should examine if the font size produces the optimal results. Follow the steps below:

  1. According to Table 2.1, “List of PDF417 fonts”, MRV PDF417 N3 produces barcodes with X dimension at 13.35 mils at 12 points. Now translate it into inches and multiply the result by the printer resolution: 13.35x0.001*203=2.71.

  2. 2.71 is not a optimized value so we either round to 3, or 2. 3 will render X dimension as 3*1000/203=14.77 mils. The optimal font size therefore is 14.77*12/13.35=13.28 points.

  3. Change the font size of the barcode text box to 13.28 points. Now the barcode produced will have high quality when printed on target printers.

8.3. Deployment

The Reporting Service require any custom assembly defined in the security policy otherwise a run-time error will be thrown and all you get is #Error without any explanation. Follow the steps below to change security policy. Two security policy files are required to change:

  • RSPreviewPolicy.config. This policy file is used for DebugLocal preview in Visual Studio. This file is located in the Report Designer folder which is [Program Files]Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies for Visual Studio 2010. Locate the according directory if you are using a different version of Visual Studio.

  • rssrvpolicy.config, the policy file used for running Report Server. The file is located under [Program Files]Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin directory.

Perform the following steps to add security policy required to run custom assembly:

  1. Open RSPreviewPolicy.config, and add the following content at the end (just before two ending CodeGroup tags):[5]

    <CodeGroup class="FirstMatchCodeGroup" 
      version="1" 
      PermissionSetName="FullTrust"
      Name="ReportServicePlugin_PDF417.dll" Description="ReportServicePlugin_PDF417.dll">
      <IMembershipCondition class="UrlMembershipCondition" version="1"
    Url="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE" \
    "PrivateAssemblies\ReportServicePlugin_PDF417.dll"/>
    </CodeGroup>
  2. Save the file. In Visual Studio, change the active configuration to DebugLocal and run the report. You should see the barcodes on the report. Examine the contents in the Output window.

    If you see message A first chance exception of type 'System.Security.SecurityException' occurred in mscorlib.dll, the security is not configured properly.

  3. After you have successfully run the report under DebugLocal configuration, publish the report to the Report Server. Open rssrvpolicy.config and add similar lines.

    <CodeGroup class="FirstMatchCodeGroup" 
      version="1" 
      PermissionSetName="FullTrust"
      Name="ReportServicePlugin_PDF417.dll" Description="ReportServicePlugin_PDF417.dll">
      <IMembershipCondition class="UrlMembershipCondition" version="1"
    Url="C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\" \
    "ReportServer\bin\ReportServicePlugin_PDF417.dll" />
      </CodeGroup>

    Note that you may change the file path if it is located in a different location.

  4. Restart SQL Server Reporting Service and browse the report. You should see the barcodes on the report this time.



[5] The value for Url attribute is too long to print in a single line If you copy the code verbatim, combine the two lines together manually. Do the same for the next XML snippet.