FYPJ
asked on
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("CrystalRepor ts.ObjectF actory")
' 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("P ATH_TRANSL ATED")
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("C rystalClie ntDoc.Repo rtClientDo cument")
' 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").Rep ortAppServ er = "[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
crReportExportFormatCrysta lReports = 0 'Crystal Report
crReportExportFormatMSWord = 1 'Microsoft Word
crReportExportFormatMSExce l = 2 'Microsoft Excel
crReportExportFormatRTF = 3 'Rich Text Format
crReportExportFormatPDF = 5 'Adobe PDF
crReportExportFormatRecord ToMSExcel = 6 'Microsoft Excel (Data Only)
crExportFormatText = 7 'Plain Text
crReportExportFormatCharac terSeparat edValues = 8 'Comma Separated Values
' Retrieve byteArray from the PrintOutputController
Set byteArray = oClientDoc.PrintOutputCont roller.Exp ort(crRepo rtExportFo rmatPDF)
'========================= ========== ========== ========== ========== =
' 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=CrystalRe port.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
%>
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("CrystalRepor
' 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("P
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("C
' 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").Rep
' 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
crReportExportFormatCrysta
crReportExportFormatMSWord
crReportExportFormatMSExce
crReportExportFormatRTF = 3 'Rich Text Format
crReportExportFormatPDF = 5 'Adobe PDF
crReportExportFormatRecord
crExportFormatText = 7 'Plain Text
crReportExportFormatCharac
' Retrieve byteArray from the PrintOutputController
Set byteArray = oClientDoc.PrintOutputCont
'=========================
' 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=CrystalRe
' 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
%>
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
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
ASKER
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!
no defined".
Where should I or how should I place the codes and does it clash with my current program?/
Thanks!
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
With crExportOptions
.DestinationOptions =
you should get a popup of valid values. Pick the one that is for disk file
mlmcc
ASKER
Sorry I'm a rookie so is it possible to explain in details wat u mean in the previous post?
Thanks alot!
Thanks alot!
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 .QueryStri ng("FileNa me"))
Response.End()
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
Response.End()
ASKER
Hi,
I'm still getting the "Class not defined: 'DiskFileDestinationOption s'" error.
Must I import or add something?
Is there a sample code somewhere for such a situation? I'm kinda lost here.
I'm still getting the "Class not defined: 'DiskFileDestinationOption
Must I import or add something?
Is there a sample code somewhere for such a situation? I'm kinda lost here.
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.MapP ath(".") & "\" & "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'.
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.MapP
• To save the byteArray to a different folder, use the following sample code:
byteArray.save("C:\export.
====================
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'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey thanks Shay79 thats what i need.
glad to help!
This is what I use for Version 10 - should be similar to 9
crDiskFileDestinationOptio
crExportOptions = crReportDocument.ExportOpt
crDiskFileDestinationOptio
'set the required report ExportOptions properties
With crExportOptions
.DestinationOptions = crDiskFileDestinationOptio
.ExportDestinationType = ExportDestinationType.Disk
.ExportFormatType = ExportFormatType.PortableD
End With
crReportDocument.Export()