ActiveReports 14 .NET Edition
ActiveReports 14 User Guide / Export Reports / Rendering Extensions / Rendering to PDF
In This Topic
    Rendering to PDF
    In This Topic

    Portable Document Format (PDF), is a format recommended for printing and for preserving formatting. You can use the PDFRenderingExtension to render your report in this format. With the PDF rendering extension, you can use features such as font linking, digital signatures and end-user defined characters (EUDC). These features are only available in the Professional Edition of ActiveReports.

    The following steps provide an example of rendering a report in PDF format.

    1. Create a new Visual Studio project.
    2. In the New Project dialog that appears, select ActiveReports 14 Page Report Application and specify a name for the project in the Name field.
    3. Click OK to create a new ActiveReports 14 Page Report Application. By default a Page report is added to the project.
    4. Add reference to GrapeCity.ActiveReports.Export.Pdf package in the project.
    5. On the Form.cs or Form.vb that opens, double-click the title bar to create the Form_Load event.
    6. Add the following code inside the Form_Load event.

     

    Visual Basic.NET code. Paste INSIDE the Form Load event.
    Copy Code
    ' Provide the page report you want to render.
    Dim rptPath As New IO.FileInfo("..\..\PageReport1.rdlx")
    Dim pageReport As New GrapeCity.ActiveReports.PageReport(rptPath)
    
    ' Create an output directory.
    Dim outputDirectory As New System.IO.DirectoryInfo("C:\MyPDF")
    outputDirectory.Create()
    
    ' Provide settings for your rendering output.
    Dim pdfSetting As New GrapeCity.ActiveReports.Export.Pdf.Page.Settings()
    
    ' Set the rendering extension and render the report.
    Dim pdfRenderingExtension As New GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension()
    Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name))
    
    ' Overwrite output file if it already exists
    outputProvider.OverwriteOutputFile = True
    
    pageReport.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting)
    
    C# code. Paste INSIDE the Form Load event.
    Copy Code
    // Provide the page report you want to render.
    System.IO.FileInfo rptPath = new System.IO.FileInfo(@"..\..\PageReport1.rdlx");
    GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(rptPath);
    
    // Create an output directory.
    System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyPDF");
    outputDirectory.Create();
    
    // Provide settings for your rendering output.
    GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
    
    // Set the rendering extension and render the report.
    GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
    GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
                
    // Overwrite output file if it already exists
    outputProvider.OverwriteOutputFile = true;
    
    pageReport.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting);
    

    PDF Rendering Properties

    ActiveReports offers a number of options to control how reports render to PDF.

    Property Description
    Application Set the value that appears for application in the Document Properties dialog of the PDF viewer application.
    Author Enter the name of the author to appear in the Document Properties dialog of the PDF viewer application.
    CenterWindow Set to True to position the document's window in the center of the screen.
    DisplayMode Specifies how the document is displayed when opened. FullScreen mode displays the document with no menu bar, window controls, or any other window visible.
    DisplayTitle Set to True to display text you enter in the Title property. When set to False it displays the name of the PDF file.
    DpiX Set the horizontal resolution of the rendered PDF file.
    DpiY Set the vertical resolution of the rendered PDF file.
    EmbedFonts

    Select how the fonts used in the report should be embedded in the PDF document.

    Note: By default, all fonts get embedded in the exported PDF document.

    Encrypt Determines whether the document is encrypted or not.
    Note: If Encrypt is set to False, permissions and passwords have no effect. 
    EndPage The last page of the report to render. The default value is the value for StartPage, that is, 0.  
    FallbackFonts Gets or sets a comma-delimited string of font families to locate missing glyphs from the original font.
    FitWindow True to resize the document’s window to fit the size of the first displayed page. Default value: false.
    HideMenubar True to hide the viewer application’s menu bar when the document is active. Default value: false.  
    HideToolbar True to hide the viewer application’s toolbars when the document is active. Default value: false.
    HideWindowUI True to hide user interface elements in the document’s window (such as scroll bars and navigation controls), leaving only the document’s contents displayed. Default value: false.
    ImageInterpolation Interpolation value of images. Allows to enable/disable image interpolation, when exporting the file to PDF.
    Keywords Keywords associated with the document. 
    MarginBottom The bottom margin value, in inches, to set for the report. You must include an integer or decimal value followed by "in" (for example, 1in). This value overrides the report's original settings.
    MarginLeft The left margin value, in inches, to set for the report. You must include an integer or decimal value followed by "in" (for example, 1in). This value overrides the report's original settings.  
    MarginRight The right margin value, in inches, to set for the report. You must include an integer or decimal value followed by "in" (for example, 1in). This value overrides the report's original settings.  
    MarginTop The top margin value, in inches, to set for the report. You must include an integer or decimal value followed by "in" (for example, 1in). This value overrides the report's original settings.  
    OwnerPassword The owner password that can be entered in the reader that permits full access to the document regardless of the specified user permissions.  
    PageHeight The page height value, in inches, to set for the report. You must include an integer or decimal value followed by "in" (for example, 1in). This value overrides the report's original settings.  
    PageWidth The page width value, in inches, to set for the report. You must include an integer or decimal value followed by "in" (for example, 1in). This value overrides the report's original settings.
    Permissions Specifies the user permissions for the document. Permissions can be combined using a comma between values. In order to use AllowFillin, AllowAccessibleReaders, and AllowAssembly permissions, you must set the Use128Bit property to True.
    PrintLayoutMode Specifies layout mode to be used for PDF document.
    PrintOnOpen Gets or sets the value indicating whether the document should be printed after open.
    PrintPresets Gets or sets the PDF print preset dialog.
    SizeToFit Determines whether PDF pages are fit to the selected paper size or not.
    StartPage The first page of the report to render. A value of 0 indicates that all pages are rendered.
    Subject The subject of the document.
    Title The title of the document.
    Use128Bit True to use 128 bit encryption with full permissions capability. False to use 40 bit encryption with limited permissions
    UserPassword The user password that can be entered in the reader. If this value is left empty, the user will not be prompted for a password, however the user will be restricted by the specified permissions.
    WatermarkAngle Specify the degree of angle for the watermark text on the PDF document. Valid values range from 0 to 359, where 0 is horizontal, left to right.
    WatermarkColor Select a color for the watermark text on the PDF document. The default value for the watermark color is gray, but you can select any Web, System, or Custom color.
    WatermarkFont Set the font to use for the watermark to any valid System.Drawing.Font.
    WatermarkTitle

    Enter text (i.e. CONFIDENTIAL) to use as the watermark on the PDF document.

     

    PDF Print Presets Properties

    ActiveReports allows you to preset the printing properties for PDF report exports using the PrintPresets class. This prepopulates the print settings in the Print dialog box. Please see Use PDF Printing Presets for more information.

    Note: The print preset properties are only available with the Professional Edition license. An evaluation message is displayed when used with the Standard Edition license.
    Property Description
    PageScaling Specify scaling for the printable area.You can select Default to shrink to the printable area, or you can select None for the actual size.
    DuplexMode

    Specify the duplex mode of the printer. For the best results with the duplex option, the selected printer should support duplex printing. You can choose from the following values,

    • Simplex: Prints on one side of the paper. This is the default value.
    • Duplex (Flip on long edge): Prints on both sides of the paper with paper flip on the long edge.
    • Duplex (Flip on short edge): Prints on both sides of the paper with paper flip on the short edge.
    PaperSourceByPageSize Determines the output tray based on PDF page size, rather than page setting options. This option is useful when printing PDFs with multiple page sizes, where different sized output trays are available. By default, this option is set to False.
    PrintPageRange Specify the range of page numbers as 1-3 or 1, 2, 3.
    NumberOfCopies Specify the number of copies to print. You can select any number of copies from 2 to 5, or select Default to specify a single copy.
    Note: These properties are available in PDF version 1.7 or higher. The PageScaling property is supported in PDF version 1.6.

     

    Interactivity

    PDF is considered as the best format for printing and it also supports interactive features like Document Map, Bookmarks and Hyperlinks. However, in case you have any data hidden (like in a drill-down report) at the time of rendering, it does not show up in the output. Therefore, it is recommended to expand all toggle items prior to rendering.

    Editable PDF: InputField Control

    In Page and RDL reports, you can use the InputField report control. This control provides support for editable fields in an exported PDF report file where the InputField’s value can be modified.

    There are two (2) types of InputField - Text and Checkbox, which you can set in the InputType property. Each type has its own set of properties: the Text type of the InputField control gets the set of properties of the TextBox control. If the Checkbox type is selected, then the new control inherits the set of properties of the CheckBox control. 

    InputField report control

    InputField report control

    Note: The InputField control is part of the Professional Edition. With the Standard license, the InputField control is not displayed in an exported file.

    Metadata in PDFs

    Adding Metadata

    An examplle of adding metadescriptions

    Metadata such as keywords, descriptions are used by the search engines to narrow down the searches. You can add a number of predefined accessors, such as title, contributors, creators, copyright, description, etc using AdditionalMetadata property. The allowed namespaces are:

    C# code. Paste INSIDE the Form Load event.
    Copy Code
    // Provide the page report you want to render.
    System.IO.FileInfo rptPath = new System.IO.FileInfo(@"..\..\PageReport1.rdlx");
    GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(rptPath);
    // Create an output directory.
    System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyPDF");
    outputDirectory.Create();         
    // Add meta data.
    var pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
    // using GrapeCity.ActiveReports.Export.Pdf;
    pdfSetting.AdditionalMetadata.Add(new AdditionalMetadataInfo
    {
        Namespace = AdditionalMetadataNamespace.PurlOrg, // Dublin Core Properties
        Key = "title",
        Value = "Invoice"
    });
    GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
    GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
    outputProvider.OverwriteOutputFile = true;
    pageReport.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting);
    

     

    Adding Attachment

    An example of adding an attachment

    You can include an attachment as metadata (such as invoices) to exported PDFs using Attachments property. This property allows to attach files such as a .xml or a .txt file in PDF. Below is the code example to export RDL and Page reports to PDF and attach a file to the exported PDF.

    VB code. Paste INSIDE the Form Load event.
    Copy Code
    ' Provide the page report you want to render.
    Dim rptPath As System.IO.FileInfo = New System.IO.FileInfo("..\..\PageReport1.rdlx")
    Dim pageReport As GrapeCity.ActiveReports.PageReport = New GrapeCity.ActiveReports.PageReport(rptPath)
    ' Create an output directory.
    Dim outputDirectory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo("C:\MyPDF")
    outputDirectory.Create()
    ' Add attachment.
    Dim pdfSetting = New GrapeCity.ActiveReports.Export.Pdf.Page.Settings()
    pdfSetting.Attachments.Add(New AttachmentInfo With {
       .Name = "file.txt",
       .Content = System.IO.File.ReadAllBytes("D:\Reports\file.txt"),
       .Description = "attachment description" ' optional
    })
    Dim pdfRenderingExtension As GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension = New GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension()
    Dim outputProvider As GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider = New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name))
    outputProvider.OverwriteOutputFile = True
    pageReport.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting)
    
    C# code. Paste INSIDE the Form Load event.
    Copy Code
    // Provide the page report you want to render.
    System.IO.FileInfo rptPath = new System.IO.FileInfo(@"..\..\PageReport1.rdlx");
    GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(rptPath);
    // Create an output directory.
    System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyPDF");
    outputDirectory.Create();
    // Add attachment.
    var pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
    // using GrapeCity.ActiveReports.Export.Pdf;        
    pdfSetting.Attachments.Add(new AttachmentInfo
    {
        Name = "file.txt",
        Content = System.IO.File.ReadAllBytes(@"D:\Reports\file.txt"),
        Description = "attachment description" // optional
    });
    // or
    //{
    //   Name = "file.xml",
    //   Content = File.ReadAllBytes(Application.StartupPath + "\\file.xml")
    //};
    GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
    GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
    outputProvider.OverwriteOutputFile = true;
    pageReport.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting);
    

    Open the exported PDF and you should see the attachment. Check the left sidebar in Adobe Acrobat Reader DC.

    Note: Metadata in PDFs is part of the Professional Edition. It is supported with the PDF version PDF/A-3b (or higher).

    PDF/A Support Limitations

    See Also