• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

Program to save CR9 generated PDF into system

Hi,

I have a sample code that automatically exports a Crystal Report into PDF and displays it in a browser.

What I need to do now is to save this .pdf file into my harddisk without having the user to manually click File->Save As...

Is there an object or function to execute such a task?

I'm using ASP.

Here is the sample code I'm using.



<%@ Language=VBScript CodePage=65001 %>

<%
'=====================================================================
' WORKING WITH RAS AND ASP TO EXPORT REPORTS
'=====================================================================

' This line creates a string variable called reportName that we will use to pass
' the Crystal Report file name (.rpt file) to the OpenReport method

reportName = "SimpleReportExport.rpt"

' Use the Object Factory object to create other RAS objects (useful for versioning changes)
Set objFactory = CreateObject("CrystalReports.ObjectFactory")
      
' This "While/Wend" loop is used to determine the physical path (eg: C:\) to the
' Crystal Report .rpt by translating the URL virtual path (eg: http://Domain/Dir)  
Dim path, iLen
path = Request.ServerVariables("PATH_TRANSLATED")                    
While (Right(path, 1) <> "\" And Len(path) <> 0)                      
iLen = Len(path) - 1                                                  
path = Left(path, iLen)                                              
Wend      
                                                                                                                                   
' Create a new ReportClientDocument object
Set oClientDoc = objFactory.CreateObject("CrystalClientDoc.ReportClientDocument")

' Specify the RAS Server (computer name or IP address) to use.
' This property should be used ONLY when the SDK and RAS Service are running on separate machines.
'Session("oClientDoc").ReportAppServer = "[COMPUTER NAME]"

' Open the report object to initialize the ReportClientDocument
oClientDoc.Open path & reportName


'==================================================================
' WORKING WITH PRINT OUTPUT CONTROLLER
'==================================================================

Dim byteArray, bufArray

' Constants - All available export format types
crReportExportFormatCrystalReports = 0                        'Crystal Report
crReportExportFormatMSWord  = 1                               'Microsoft Word
crReportExportFormatMSExcel = 2                                    'Microsoft Excel
crReportExportFormatRTF = 3                                          'Rich Text Format
crReportExportFormatPDF = 5                                          'Adobe PDF
crReportExportFormatRecordToMSExcel = 6                        'Microsoft Excel (Data Only)
crExportFormatText = 7                                                'Plain Text
crReportExportFormatCharacterSeparatedValues = 8      'Comma Separated Values


' Retrieve byteArray from the PrintOutputController
Set byteArray = oClientDoc.PrintOutputController.Export(crReportExportFormatPDF)


'==================================================================
' SETUP THE RESPONSE OBJECT ATTRIBUTES
'==================================================================

' Clear the Response object
Response.Clear

' Add a custom header for an inline file type with a default file name
Response.AddHeader "content-disposition", "inline;filename=CrystalReport.pdf"

' Set the Content Type to application/pdf
Response.ContentType = "application/pdf"

' Send the bytearray to the browser through the Response object, used
' detachArray method for quicker tranfer of data
Response.BinaryWrite byteArray.detachArray

%>
0
FYPJ
Asked:
FYPJ
  • 5
  • 4
  • 2
1 Solution
 
Shay79Commented:
hi
This is what I use for Version 10 - should be similar to 9
  crDiskFileDestinationOptions = New DiskFileDestinationOptions
  crExportOptions = crReportDocument.ExportOptions
 crDiskFileDestinationOptions.DiskFileName = FileName 'path of where to save file

            'set the required report ExportOptions properties
            With crExportOptions
                .DestinationOptions = crDiskFileDestinationOptions
                .ExportDestinationType = ExportDestinationType.DiskFile
                .ExportFormatType = ExportFormatType.PortableDocFormat
            End With
crReportDocument.Export()
0
 
mlmccCommented:
That should work with CR9.  However you will only get the file saved and not displayed.

If you want it displayed and saved you either have to let the user save it, save it and use calls to open the PDF file, or basically rubn the report twice (once to save then again to display it).

mlmcc
0
 
FYPJAuthor Commented:
Thanks guys! I have tried placing the codes at the end of my program but there is an error msg that says " DiskFileDestinationOptions
 no defined".

Where should I or how should I place the codes and does it clash with my current program?/

Thanks!
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mlmccCommented:
When you enter this part

            With crExportOptions
                .DestinationOptions =

you should get a popup of valid values.  Pick the one that is for disk file

mlmcc
0
 
FYPJAuthor Commented:
Sorry I'm a rookie so is it possible to explain in details wat u mean in the previous post?

Thanks alot!
0
 
Shay79Commented:
Hi
The destination options define where it will be exported to. If you look for this in you object manager you should see a list of valid values (eg: File).

Then after its been exported to pdf, you can display it by passing the filename to a new page, and in the code display it

Response.ContentType = "Application/pdf"
Response.WriteFile(Request.QueryString("FileName"))
Response.End()
0
 
FYPJAuthor Commented:
Hi,

I'm still getting the "Class not defined: 'DiskFileDestinationOptions'" error.

Must I import or add something?

Is there a sample code somewhere for such a situation? I'm kinda lost here.
0
 
Shay79Commented:
Hi

The code I posted was just a pointer, as I mentioned its for version 10. But I actually just did a quick search on the Business Objects website and found this snippet- please note I havent tried it as I am running version 10


Symptom
When you export a report to disk using either the Crystal Enterprise (CE) or Report Application Server (RAS) SDK, how can you save the resulting ByteArray object to disk?

Resolution
To save the ByteArray object to disk, use the 'Save' method as follows:


• To save the ByteArray to the web application folder, use the following sample code:


byteArray.save(Server.MapPath(".") & "\" & "export.pdf")


• To save the byteArray to a different folder, use the following sample code:


byteArray.save("C:\export.pdf")


====================

NOTE:


When saving the ByteArray to a folder other than the application folder, explicitly give the user account under which IIS is running write access to this folder by completing these steps:


1. Right-click the folder and click 'Properties'.


2. Click the 'Security' tab.


3. Click the 'Add' button. The 'Select Users, Computers, or Groups' dialog box appears.


4. Type the name of the user account under which IIS is running.


5. Click 'OK'.


6. Select the 'Write' box.


7. Click 'OK'.

0
 
Shay79Commented:
I actually just tested with RAS 10 & it works

i placed the line in the code as follows

Response.BinaryWrite oByteArray.ByteArray
oByteArray.save("c:\temp\t.pdf")
0
 
FYPJAuthor Commented:
Hey thanks Shay79 thats what i need.
0
 
Shay79Commented:
glad to help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now