?
Solved

pdf export with reportID instead of path and  filename

Posted on 2005-03-01
9
Medium Priority
?
483 Views
Last Modified: 2008-01-09
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

%>
------------------------------
0
Comment
Question by:Stella Pauley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 13429724
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
0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 13429861
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}

0
 
LVL 101

Expert Comment

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

mlmcc
0
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
LVL 1

Author Comment

by:Stella Pauley
ID: 13436268
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...
0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 13443490
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

%>
------------------------------------------------------------------------
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 2000 total points
ID: 13446915
Is the report saved with data?

mlmcc
0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 13448678
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..
0
 
LVL 1

Author Comment

by:Stella Pauley
ID: 13450779
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

%>

------------------
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 13454667
Glad i could help

mlmcc
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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