Vb.net – how to set password to pdf file while exporting from crystal report in vb.net programatically

crystal-reportsvb.net

I have written a code which creates a pdf file exporting from Crystal Reports in VB.NET 2005.
All the code is working fine and also PDF files are created ok, but I want to set a password to that PDF file programatically.
Is there any solution?

Below is my code to create PDF files while exporting from Crystal Reports

Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()

CrDiskFileDestinationOptions.DiskFileName = "D:\PDFFiles\" & fileName

CrFormatTypeOptions.FirstPageNumber = 1 ' Start Page in the Report

CrFormatTypeOptions.LastPageNumber = 10 ' End Page in the Report

CrFormatTypeOptions.UsePageRange = True


CrExportOptions = CrReport.ExportOptions

With CrExportOptions

    .ExportDestinationType = ExportDestinationType.DiskFile
    .ExportFormatType = ExportFormatType.PortableDocFormat

    .DestinationOptions = CrDiskFileDestinationOptions

    .FormatOptions = CrFormatTypeOptions

End With
CrReport.Export()

Best Answer

As far as I know, Crystal Reports can export to PDF format but can't put any password protection on the resulting file (see one of many similar posts here). There are third party tools that you can use to protect the resulting PDFs, but you can't do it during the export. There is one post I found that mentions a successful export with password protection, but after unsuccessfully trying to navigate the mentioned site I gave up. Check it out for yourself here and maybe you have more luck.

Chris

Related Topic