Stella Pauley
asked on
pdf export with reportID instead of path and filename
I know how to open a report via ASP when using the full path and filename with ReportClientDocument.Open. .
Then export to a PDF that displays in the browser with PrintOutputController.Expo rt..
But how can I open the report using the 'reportid'..
I am attempting to alter the following code to export to pdf...
-------------------------- ---------- ---------- --------
<%@ Language=VBScript codepage=65001%>
<% Option Explicit
Response.ExpiresAbsolute = Now() - 1
const CLOSED_RPT_ID = "closedreportid"
const RPT_ID = "reportid"
const RPT_SOURCE = "reportsource"
Dim requestMethod
requestMethod = UCase(Request.ServerVariab les("REQUE ST_METHOD" ))
Dim serializedRptSrc, reportid, closedreportid
if (requestMethod = "POST") then
serializedRptSrc = Request.Form(RPT_SOURCE)
closedreportid = Request.Form(CLOSED_RPT_ID )
else
serializedRptSrc = Request.QueryString(RPT_SO URCE)
closedreportid = Request.QueryString(CLOSED _RPT_ID)
end if
' reportid is always passed in the URL
reportid = Request.QueryString(RPT_ID )
if (Not (IsEmpty(closedreportid) OR (Len(closedreportid) = 0))) then
' Clear the report source in session with the given closedreportid
Session.Contents.Remove(cl osedreport id)
end if
if (Not (IsEmpty(reportid) OR (Len(reportid) = 0))) then
On Error Resume Next
Dim objectFactory
' Use the version dependent prog id for side by side support
' (i.e. to maintain consistency when multiple versions of the product is installed)
Set objectFactory = CreateObject("CrystalRepor ts11.Objec tFactory.1 ")
Dim HTMLViewer
Set HTMLViewer = ObjectFactory.CreateObject ("CrystalR eports.Cry stalReport Viewer")
With HTMLViewer
.Name = "htmlpreview"
.IsOwnForm = true
.IsOwnPage = true
.HasRefreshButton = false
.HasExportButton = false
.HasPrintButton = false
End With
if (Not (IsEmpty(serializedRptSrc) OR (Len(serializedRptSrc) = 0))) then
' Got a seralizedRprtSrc string
' need to deserialize the report source string and pass to viewer
Dim XMLSerializer
Set XMLSerializer = ObjectFactory.CreateObject ("CrystalR eports.SAX XMLSeriali zer")
XMLSerializer.SetObjectCre ator ObjectFactory
HTMLViewer.ReportSource = XMLSerializer.CreateObject FromString (serialize dRptSrc)
set Session.Contents(reportid) = HTMLViewer.ReportSource
else
' Try to load report source from session
HTMLViewer.ReportSource = Session.Contents(reportid)
end if
HTMLViewer.URI = Request.ServerVariables("P ath_Info") + "?" + RPT_ID + "=" + reportid
call HTMLViewer.ProcessHttpRequ est(Reques t, Response, Session)
if Err.number <> 0 then
Response.Write Err.Description
Err.Clear
end if
end if
%>
-------------------------- ----
Then export to a PDF that displays in the browser with PrintOutputController.Expo
But how can I open the report using the 'reportid'..
I am attempting to alter the following code to export to pdf...
--------------------------
<%@ Language=VBScript codepage=65001%>
<% Option Explicit
Response.ExpiresAbsolute = Now() - 1
const CLOSED_RPT_ID = "closedreportid"
const RPT_ID = "reportid"
const RPT_SOURCE = "reportsource"
Dim requestMethod
requestMethod = UCase(Request.ServerVariab
Dim serializedRptSrc, reportid, closedreportid
if (requestMethod = "POST") then
serializedRptSrc = Request.Form(RPT_SOURCE)
closedreportid = Request.Form(CLOSED_RPT_ID
else
serializedRptSrc = Request.QueryString(RPT_SO
closedreportid = Request.QueryString(CLOSED
end if
' reportid is always passed in the URL
reportid = Request.QueryString(RPT_ID
if (Not (IsEmpty(closedreportid) OR (Len(closedreportid) = 0))) then
' Clear the report source in session with the given closedreportid
Session.Contents.Remove(cl
end if
if (Not (IsEmpty(reportid) OR (Len(reportid) = 0))) then
On Error Resume Next
Dim objectFactory
' Use the version dependent prog id for side by side support
' (i.e. to maintain consistency when multiple versions of the product is installed)
Set objectFactory = CreateObject("CrystalRepor
Dim HTMLViewer
Set HTMLViewer = ObjectFactory.CreateObject
With HTMLViewer
.Name = "htmlpreview"
.IsOwnForm = true
.IsOwnPage = true
.HasRefreshButton = false
.HasExportButton = false
.HasPrintButton = false
End With
if (Not (IsEmpty(serializedRptSrc)
' Got a seralizedRprtSrc string
' need to deserialize the report source string and pass to viewer
Dim XMLSerializer
Set XMLSerializer = ObjectFactory.CreateObject
XMLSerializer.SetObjectCre
HTMLViewer.ReportSource = XMLSerializer.CreateObject
set Session.Contents(reportid)
else
' Try to load report source from session
HTMLViewer.ReportSource = Session.Contents(reportid)
end if
HTMLViewer.URI = Request.ServerVariables("P
call HTMLViewer.ProcessHttpRequ
if Err.number <> 0 then
Response.Write Err.Description
Err.Clear
end if
end if
%>
--------------------------
ASKER
in a way..
Im working with the new Crystal Reports XI Developer and Server..
The developer has a button 'HTML Preview' that launches the asp code that I included above with the following url..
http://server/crystalreportviewers11/preview.asp?reportid={01C07995-D6E2-4F90-A445-1 6A5B54136E 4}
Im working with the new Crystal Reports XI Developer and Server..
The developer has a button 'HTML Preview' that launches the asp code that I included above with the following url..
http://server/crystalreportviewers11/preview.asp?reportid={01C07995-D6E2-4F90-A445-1
No idea. That is a new feature for CR XI that I hadn't heard or read about.
mlmcc
mlmcc
ASKER
Im getting close.. I got it to work once...
but when I closed it and re-ran it.. It started coming up with a blank window.. no error.. no report...
I'll keep working on it and will update once I get it working better...
but when I closed it and re-ran it.. It started coming up with a blank window.. no error.. no report...
I'll keep working on it and will update once I get it working better...
ASKER
Well.. I've got it working.. however.. when you hit the HTMLPreview button.. you get a blank window.. then if you hit the refresh button the PDF will load.. I don't know why it works this way and I can't figure out a way to auto refresh it..
I tried response.redirect but it still works the same way..
Here is what I have:
-------------------------- ---------- ---------- ---------- ---------- ------
<%@ Language=VBScript codepage=65001%>
<% Option Explicit
On Error Resume Next
Response.ContentType="appl ication/pd f"
Response.ExpiresAbsolute = Now() - 1
const CLOSED_RPT_ID = "closedreportid"
const RPT_ID = "reportid"
const RPT_SOURCE = "reportsource"
Dim requestMethod
requestMethod = UCase(Request.ServerVariab les("REQUE ST_METHOD" ))
Dim serializedRptSrc, reportid, closedreportid
if (requestMethod = "POST") then
serializedRptSrc = Request.Form(RPT_SOURCE)
closedreportid = Request.Form(CLOSED_RPT_ID )
else
serializedRptSrc = Request.QueryString(RPT_SO URCE)
closedreportid = Request.QueryString(CLOSED _RPT_ID)
end if
' reportid is always passed in the URL
reportid = Request.QueryString(RPT_ID )
if (Not (IsEmpty(closedreportid) OR (Len(closedreportid) = 0))) then
' Clear the report source in session with the given closedreportid
Session.Contents.Remove(cl osedreport id)
end if
if (Not (IsEmpty(reportid) OR (Len(reportid) = 0))) then
Dim objectFactory
' Use the version dependent prog id for side by side support
' (i.e. to maintain consistency when multiple versions of the product is installed)
Set objectFactory = CreateObject("CrystalRepor ts11.Objec tFactory.1 ")
Dim expOpt, formatOpt
Set expOpt = ObjectFactory.CreateObject ("CrystalR eports.Exp ortOptions ")
Set formatOpt = ObjectFactory.CreateObject ("CrystalR eports.PDF ExportForm atOptions" )
Dim crReportExportFormatPDF
crReportExportFormatPDF = 5
expOpt.FormatOptions = formatOpt
expOpt.ExportFormatType = crReportExportFormatPDF
Dim exportControl ', rptFactory, rptSource
Set exportControl = Server.CreateObject("Cryst alReports. CrystalRep ortExportC ontrol")
Dim HTMLViewer
Set HTMLViewer = ObjectFactory.CreateObject ("CrystalR eports.Cry stalReport Viewer")
if (Not (IsEmpty(serializedRptSrc) OR (Len(serializedRptSrc) = 0))) then
' Got a seralizedRprtSrc string
' need to deserialize the report source string and pass to viewer
Dim XMLSerializer
Set XMLSerializer = ObjectFactory.CreateObject ("CrystalR eports.SAX XMLSeriali zer")
XMLSerializer.SetObjectCre ator ObjectFactory
HTMLViewer.ReportSource = XMLSerializer.CreateObject FromString (serialize dRptSrc)
set Session.Contents(reportid) = HTMLViewer.ReportSource
else
end if
'------EXPORT-----
With exportControl
'.EnterpriseLogon = iStore.EnterpriseSession
.ReportSource = Session.Contents(reportid)
.Name = "PreviewPDF"
.IsOwnForm = true
.IsOwnPage = true
.ExportOptions = expOpt
.ExportAsAttachment = false
End With
exportControl.ProcessHttpR equest Request, Response, Session
'-------
if Err.number <> 0 then
Response.Write Err.Description
Err.Clear
end if
end if
%>
-------------------------- ---------- ---------- ---------- ---------- ------
I tried response.redirect but it still works the same way..
Here is what I have:
--------------------------
<%@ Language=VBScript codepage=65001%>
<% Option Explicit
On Error Resume Next
Response.ContentType="appl
Response.ExpiresAbsolute = Now() - 1
const CLOSED_RPT_ID = "closedreportid"
const RPT_ID = "reportid"
const RPT_SOURCE = "reportsource"
Dim requestMethod
requestMethod = UCase(Request.ServerVariab
Dim serializedRptSrc, reportid, closedreportid
if (requestMethod = "POST") then
serializedRptSrc = Request.Form(RPT_SOURCE)
closedreportid = Request.Form(CLOSED_RPT_ID
else
serializedRptSrc = Request.QueryString(RPT_SO
closedreportid = Request.QueryString(CLOSED
end if
' reportid is always passed in the URL
reportid = Request.QueryString(RPT_ID
if (Not (IsEmpty(closedreportid) OR (Len(closedreportid) = 0))) then
' Clear the report source in session with the given closedreportid
Session.Contents.Remove(cl
end if
if (Not (IsEmpty(reportid) OR (Len(reportid) = 0))) then
Dim objectFactory
' Use the version dependent prog id for side by side support
' (i.e. to maintain consistency when multiple versions of the product is installed)
Set objectFactory = CreateObject("CrystalRepor
Dim expOpt, formatOpt
Set expOpt = ObjectFactory.CreateObject
Set formatOpt = ObjectFactory.CreateObject
Dim crReportExportFormatPDF
crReportExportFormatPDF = 5
expOpt.FormatOptions = formatOpt
expOpt.ExportFormatType = crReportExportFormatPDF
Dim exportControl ', rptFactory, rptSource
Set exportControl = Server.CreateObject("Cryst
Dim HTMLViewer
Set HTMLViewer = ObjectFactory.CreateObject
if (Not (IsEmpty(serializedRptSrc)
' Got a seralizedRprtSrc string
' need to deserialize the report source string and pass to viewer
Dim XMLSerializer
Set XMLSerializer = ObjectFactory.CreateObject
XMLSerializer.SetObjectCre
HTMLViewer.ReportSource = XMLSerializer.CreateObject
set Session.Contents(reportid)
else
end if
'------EXPORT-----
With exportControl
'.EnterpriseLogon = iStore.EnterpriseSession
.ReportSource = Session.Contents(reportid)
.Name = "PreviewPDF"
.IsOwnForm = true
.IsOwnPage = true
.ExportOptions = expOpt
.ExportAsAttachment = false
End With
exportControl.ProcessHttpR
'-------
if Err.number <> 0 then
Response.Write Err.Description
Err.Clear
end if
end if
%>
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
no.. but the report is running in the developer.. XI has the same preview as previous version.. (lightning bolt icon is now a print preview icon)..
but it also has an HTML preview button that uses IE as a plugin (opens in the developer not in a new browser window)...
This function requires the Crystal XI Server..
but it also has an HTML preview button that uses IE as a plugin (opens in the developer not in a new browser window)...
This function requires the Crystal XI Server..
ASKER
Well.. I gave up tring to figure it out.. and was just going to use it by hitting HTMLPreview then Hitting Refresh...
I decided to go ahead and test it with the new Adobe Reader v7.. and guess what...
It works when you hit HTMLPreview... You don't have to hit refresh...
It must have been some sort of bug in Adobe Reader v6 that I was running into...
Anyway... got it all working... Cleaned up my code a bit... Here is my final file....
-----------------
<%@ Language=VBScript codepage=65001%>
<% Option Explicit
On Error Resume Next
Response.ExpiresAbsolute = Now() - 1
const CLOSED_RPT_ID = "closedreportid"
const RPT_ID = "reportid"
const RPT_SOURCE = "reportsource"
Dim requestMethod
requestMethod = UCase(Request.ServerVariab les("REQUE ST_METHOD" ))
Dim serializedRptSrc, reportid, closedreportid
if (requestMethod = "POST") then
serializedRptSrc = Request.Form(RPT_SOURCE)
closedreportid = Request.Form(CLOSED_RPT_ID )
else
serializedRptSrc = Request.QueryString(RPT_SO URCE)
closedreportid = Request.QueryString(CLOSED _RPT_ID)
end if
' reportid is always passed in the URL
reportid = Request.QueryString(RPT_ID )
if (Not (IsEmpty(closedreportid) OR (Len(closedreportid) = 0))) then
' Clear the report source in session with the given closedreportid
Session.Contents.Remove(cl osedreport id)
end if
if (Not (IsEmpty(reportid) OR (Len(reportid) = 0))) then
Dim objectFactory
' Use the version dependent prog id for side by side support
' (i.e. to maintain consistency when multiple versions of the product is installed)
Set objectFactory = CreateObject("CrystalRepor ts11.Objec tFactory.1 ")
Dim expOpt, formatOpt
Set expOpt = ObjectFactory.CreateObject ("CrystalR eports.Exp ortOptions ")
Set formatOpt = ObjectFactory.CreateObject ("CrystalR eports.PDF ExportForm atOptions" )
Dim crReportExportFormatPDF
crReportExportFormatPDF = 5
expOpt.FormatOptions = formatOpt
expOpt.ExportFormatType = crReportExportFormatPDF
Dim exportControl
Set exportControl = Server.CreateObject("Cryst alReports. CrystalRep ortExportC ontrol")
if (Not (IsEmpty(serializedRptSrc) OR (Len(serializedRptSrc) = 0))) then
' Got a seralizedRprtSrc string
' need to deserialize the report source string and pass to viewer
Dim XMLSerializer
Set XMLSerializer = ObjectFactory.CreateObject ("CrystalR eports.SAX XMLSeriali zer")
XMLSerializer.SetObjectCre ator ObjectFactory
set Session.Contents(reportid) = XMLSerializer.CreateObject FromString (serialize dRptSrc)
end if
With exportControl
.ReportSource = Session.Contents(reportid)
.Name = "PreviewPDF"
.IsOwnForm = true
.IsOwnPage = true
.ExportOptions = expOpt
.ExportAsAttachment = true
End With
'----RUN THE REPORT----
exportControl.ProcessHttpR equest Request, Response, Session
'-------
if Err.number <> 0 then
Response.Write Err.Description
Err.Clear
end if
end if
%>
------------------
I decided to go ahead and test it with the new Adobe Reader v7.. and guess what...
It works when you hit HTMLPreview... You don't have to hit refresh...
It must have been some sort of bug in Adobe Reader v6 that I was running into...
Anyway... got it all working... Cleaned up my code a bit... Here is my final file....
-----------------
<%@ Language=VBScript codepage=65001%>
<% Option Explicit
On Error Resume Next
Response.ExpiresAbsolute = Now() - 1
const CLOSED_RPT_ID = "closedreportid"
const RPT_ID = "reportid"
const RPT_SOURCE = "reportsource"
Dim requestMethod
requestMethod = UCase(Request.ServerVariab
Dim serializedRptSrc, reportid, closedreportid
if (requestMethod = "POST") then
serializedRptSrc = Request.Form(RPT_SOURCE)
closedreportid = Request.Form(CLOSED_RPT_ID
else
serializedRptSrc = Request.QueryString(RPT_SO
closedreportid = Request.QueryString(CLOSED
end if
' reportid is always passed in the URL
reportid = Request.QueryString(RPT_ID
if (Not (IsEmpty(closedreportid) OR (Len(closedreportid) = 0))) then
' Clear the report source in session with the given closedreportid
Session.Contents.Remove(cl
end if
if (Not (IsEmpty(reportid) OR (Len(reportid) = 0))) then
Dim objectFactory
' Use the version dependent prog id for side by side support
' (i.e. to maintain consistency when multiple versions of the product is installed)
Set objectFactory = CreateObject("CrystalRepor
Dim expOpt, formatOpt
Set expOpt = ObjectFactory.CreateObject
Set formatOpt = ObjectFactory.CreateObject
Dim crReportExportFormatPDF
crReportExportFormatPDF = 5
expOpt.FormatOptions = formatOpt
expOpt.ExportFormatType = crReportExportFormatPDF
Dim exportControl
Set exportControl = Server.CreateObject("Cryst
if (Not (IsEmpty(serializedRptSrc)
' Got a seralizedRprtSrc string
' need to deserialize the report source string and pass to viewer
Dim XMLSerializer
Set XMLSerializer = ObjectFactory.CreateObject
XMLSerializer.SetObjectCre
set Session.Contents(reportid)
end if
With exportControl
.ReportSource = Session.Contents(reportid)
.Name = "PreviewPDF"
.IsOwnForm = true
.IsOwnPage = true
.ExportOptions = expOpt
.ExportAsAttachment = true
End With
'----RUN THE REPORT----
exportControl.ProcessHttpR
'-------
if Err.number <> 0 then
Response.Write Err.Description
Err.Clear
end if
end if
%>
------------------
Glad i could help
mlmcc
mlmcc
Are you trying to export a report while it is being viewed?
There is an export sample in this ASP code
http://support.businessobjects.com/communityCS/FilesAndUpdates/aspxmps10.exe.asp
mlmcc