Solved

Program to save CR9 generated PDF into system

Posted on 2006-11-15
11
331 Views
Last Modified: 2008-01-16
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
Comment
Question by:FYPJ
  • 5
  • 4
  • 2
11 Comments
 
LVL 1

Expert Comment

by:Shay79
ID: 17954672
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
 
LVL 100

Expert Comment

by:mlmcc
ID: 17958661
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
 

Author Comment

by:FYPJ
ID: 17961928
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
 
LVL 100

Expert Comment

by:mlmcc
ID: 17962477
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
 

Author Comment

by:FYPJ
ID: 17962562
Sorry I'm a rookie so is it possible to explain in details wat u mean in the previous post?

Thanks alot!
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Expert Comment

by:Shay79
ID: 17963493
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
 

Author Comment

by:FYPJ
ID: 17977052
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
 
LVL 1

Expert Comment

by:Shay79
ID: 17978184
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
 
LVL 1

Accepted Solution

by:
Shay79 earned 100 total points
ID: 17978330
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
 

Author Comment

by:FYPJ
ID: 17984861
Hey thanks Shay79 thats what i need.
0
 
LVL 1

Expert Comment

by:Shay79
ID: 17985718
glad to help!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now