Blogs

Paul Kimmel's Blog

PDF Password Security for XtraReports, new in v2009 volume 3

     

In the document wars Adobe’s PDF format seems to have won. Because they give away their Adobe Reader for free it is probably the most widely distributed document format and reader except for maybe MS-Word documents. New in XtraReports Suite v2009, volume 3 is the ability to password protect documents exported in the PDF format.

In short you can print an XtraReport and select various formats. If you select Print and Export from out demos (see Figure 1) or click the File|Export Document from the report previewer (see Figure 2) and pick the PDF format then the PDF Export Options dialog will displayed (see Figure 3). The PDF Export Options dialog has a Password Security input field. Click the ellipses to open the Password Security dialog (see Figure 4).Check Require a password to open the document and provide a password. The user will be required to repeat the password after closing the Password Security dialog (see Figure 6). If you want an additional password for changing the document then check “Restrict editing and printing of the document” and provide an additional password.

When the user attempts to open a secured document in Adobe Reader the password prompt will be displayed, and the reader will be required to provide a password. The Adobe Reader title will indicated—with the word SECURED—in the title bar when a document is password protected. Programmatically exporting a password report to PDF format couldn’t be easier—design the report, create an instance of the XtraReport object, set the XtraReport.ExportOptions.Pdf.PasswordSecurityOptions.OpenPassword and set this property with the password value (see Listing 1). [Note: if you are going to embed password information in your code then you might want to use a tool like Dotfuscator to obfuscate your code, protecting it from a disassembler.]

Listing 1: Two lines of code is all it takes to export a password protected PDF report created with XtraReports.

using System;
using System.Windows.Forms;

namespace PDFPasswordSecurity
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    XtraReport1 report = new XtraReport1();
    private void button1_Click(object sender, EventArgs e)
    {
      report.ExportOptions.Pdf.PasswordSecurityOptions.OpenPassword = "password";
      report.ExportToPdf("c:\\temp\\demo.pdf");

    }
  }
}

 

XtraReportsDemo
Figure 1: The Products List demo report exposes the export feature from the Print and Export menu. 

 XtraReportsPreview
Figure 2: The default previewer supports exporting (and mailing) from the File menu.

image 
Figure 3: The PDF Export Options dialog lets you specify a password for tthe PDF document to be exported.

image
Figure 4: Check the Require a password to open the document and provide a password in the Document Open Password field.

image
Figure 5: For a separate password for editing permissions check Restrict editing and printing of the document and provide an additional password. 

image
Figure 6: The user will be asked to confirm the password after you click OK on the Password Security dialog.

image
Figure 7: Adobe Reader will prompt the user and require the correct password before opening a password protected document. 

 

image
Figure 8: The protected document in Adobe Reader shows the the document is SECURED in the window title bar.

Published Dec 29 2009, 10:03 PM by Paul Kimmel (DevExpress)
Filed under: ,
Technorati tags: v2009.3, XtraReports
Bookmark and Share

Comments

 

Trevor Westerdahl said:

This looks great. From my view, it seems that certain reports should ALWAYS be secured, so having as a user-selectable option 'option' with unsecured as the default seems to be a problem.

So, in trying to anticipate actually using it, wouldn't the most-common scenario likely involve setting the security in code such that certain reports are always exported as 'secured' or password protected?

Seeing this just makes me think the next natural question is: "How do I set PDF export security settings in code?"; thus, it would be nice to see a link to a programmatic 'how-to'.

Very Nice! I have a need for this.

January 3, 2010 7:57 PM
 

Peter Meyer said:

Awesome Job!  Now I can eliminate a third-party PDF toolkit just for security stuff.  Thanks!!

January 3, 2010 9:40 PM
 

Paul Kimmel (DevExpress) said:

Peter:

Excellent. That is the ind of feedback we like to hear.

Paul

January 4, 2010 9:36 AM
 

Trevor said:

Yes, security will become more prevalent. Everything sent over the web has the potential to live forever. Forever is a long time,especially for sensitive data.

January 7, 2010 1:50 PM
 

Michael said:

I believe you are using the old PDF 1.6 standard, which means putting a password only fools the owner, not the attacker.

Instant recovery is possible with many tools already.

When do you plan to support later pdf versions with AES encryption?

March 28, 2010 11:25 PM
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.