Link to home
Start Free TrialLog in
Avatar of Stella Pauley
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.Export..

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.ServerVariables("REQUEST_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_SOURCE)
    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(closedreportid)
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("CrystalReports11.ObjectFactory.1")
   
    Dim HTMLViewer

    Set HTMLViewer = ObjectFactory.CreateObject("CrystalReports.CrystalReportViewer")
    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("CrystalReports.SAXXMLSerializer")
       
        XMLSerializer.SetObjectCreator ObjectFactory    
        HTMLViewer.ReportSource = XMLSerializer.CreateObjectFromString(serializedRptSrc)
       
        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("Path_Info") + "?" + RPT_ID + "=" + reportid
   
    call HTMLViewer.ProcessHttpRequest(Request, Response, Session)
    if Err.number <> 0 then
        Response.Write Err.Description
        Err.Clear
    end if          

end if

%>
------------------------------
Avatar of Mike McCracken
Mike McCracken

What is the report id?

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
Avatar of Stella Pauley

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-16A5B54136E4}

No idea. That is a new feature for CR XI that I hadn't heard or read about.

mlmcc
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...
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="application/pdf"
Response.ExpiresAbsolute = Now() - 1
const CLOSED_RPT_ID = "closedreportid"
const RPT_ID = "reportid"
const RPT_SOURCE = "reportsource"

Dim requestMethod
requestMethod = UCase(Request.ServerVariables("REQUEST_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_SOURCE)
    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(closedreportid)
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("CrystalReports11.ObjectFactory.1")

Dim expOpt, formatOpt
Set expOpt = ObjectFactory.CreateObject("CrystalReports.ExportOptions")
Set formatOpt = ObjectFactory.CreateObject("CrystalReports.PDFExportFormatOptions")

Dim crReportExportFormatPDF
crReportExportFormatPDF = 5

expOpt.FormatOptions = formatOpt
expOpt.ExportFormatType = crReportExportFormatPDF



Dim exportControl  ', rptFactory, rptSource
Set exportControl = Server.CreateObject("CrystalReports.CrystalReportExportControl")

   
    Dim HTMLViewer
    Set HTMLViewer = ObjectFactory.CreateObject("CrystalReports.CrystalReportViewer")
       
    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("CrystalReports.SAXXMLSerializer")
       
        XMLSerializer.SetObjectCreator ObjectFactory    
        HTMLViewer.ReportSource = XMLSerializer.CreateObjectFromString(serializedRptSrc)
       
        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.ProcessHttpRequest Request, Response, Session

'-------

    if Err.number <> 0 then
        Response.Write Err.Description
        Err.Clear
    end if          

end if

%>
------------------------------------------------------------------------
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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..
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.ServerVariables("REQUEST_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_SOURCE)
    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(closedreportid)
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("CrystalReports11.ObjectFactory.1")

Dim expOpt, formatOpt
Set expOpt = ObjectFactory.CreateObject("CrystalReports.ExportOptions")
Set formatOpt = ObjectFactory.CreateObject("CrystalReports.PDFExportFormatOptions")

Dim crReportExportFormatPDF
crReportExportFormatPDF = 5

expOpt.FormatOptions = formatOpt
expOpt.ExportFormatType = crReportExportFormatPDF

Dim exportControl  
Set exportControl = Server.CreateObject("CrystalReports.CrystalReportExportControl")
       
    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("CrystalReports.SAXXMLSerializer")
            XMLSerializer.SetObjectCreator ObjectFactory    

    set Session.Contents(reportid) = XMLSerializer.CreateObjectFromString(serializedRptSrc)
    end if

With exportControl
      .ReportSource = Session.Contents(reportid)
      .Name = "PreviewPDF"
      .IsOwnForm = true
      .IsOwnPage = true
      .ExportOptions = expOpt
      .ExportAsAttachment = true
End With


'----RUN THE REPORT----
  exportControl.ProcessHttpRequest Request, Response, Session

'-------

    if Err.number <> 0 then
        Response.Write Err.Description
        Err.Clear
    end if          

end if

%>

------------------
Glad i could help

mlmcc