Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to exprot crystal reprot result to PDF format only

Status
Not open for further replies.

taree

Technical User
May 31, 2008
316
US
Everything is working for me as it should. My question is can I export the result from the crystal reports to pdf format only. below is the code for my click event.

(code)
Protected Sub btnSelect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSelect.Click

System.Threading.Thread.Sleep(1000)
ClientScript.RegisterClientScriptBlock(Me.GetType, _
"reset", "document.getElementById('" & btnSelect.ClientID & "').disabled=false;", True)

Dim NamStr As String = ""
Dim LocStr As String = ""
Dim ValStr As String = ""
Dim reportId As Integer = 5721347
NamStr = "Contractid"
Dim NumP As Integer = 1

For Each gvRows As GridViewRow In gvItemDetail.Rows
Dim chkSelect As CheckBox = CType(gvRows.FindControl("chkSelect"), CheckBox)
If chkSelect.Checked Then
ValStr = ValStr & (gvItemDetail.DataKeys(gvRows.RowIndex)("contid")).ToString.Trim & ","
End If

Next

If ValStr.Length = 0 Then
lblError.Visible = True
Else
lblError.Visible = False
ValStr = Left(ValStr, Len(ValStr) - 1) & ";"
Dim Urlval As New UrlType
LocStr = Urlval.GetUrl & reportId & "&Pnames=" & NamStr & "&Pvals=" & ValStr & "&NumParens=" & NumP
Response.Redirect(LocStr)
End If

End Sub
(code)
 
This code has nothing to do with exporting data.

Once the CR view opens, the user has the ability to export the report to many formats, including .pdf.
 
Thank you Jbenson001 for reply.Will it possible to disable everything except export to PDF? Can this be done with asp.net code or this only be possilbe by disabling the other export choices from the server where the code is...
 
Hi,
Add this to your completed LocStr if it is a direct call to the report object cmd=EXPORT&EXPORT_FMTU2FPDF:0 - BUT, It appears you are calling another page to parse the URL created by LocStr so it probably needs to be edited on that page to insure its proper usage.

If you are using someting like this page:
Code:
<HTML>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=charset=UTF-8">
<BODY>
<%
'===================================================================
' AUTHOR - SG, KA
' CREATED - March 31, 2004
' Modified by Turkbear July 2005 to make it an asp page
' PURPOSE - This sample ASP application demonstrates how to view 
'           on demand a report with a multiple value parameter 
'           using the Crystal Enterprise 11 COM SDK.
' DESCRIPTION
'	- Define CE Logon Variables
'   - Create the Enterprise Session Manager and iStore objects
'   - Query the CMS for a report to view
'	- Create and pass parameter for the report
'	- Create the viewer object and view the report
'==================================================================

'Declare the CMS Logon Variables
Dim CMS
Dim Username
Dim Password
Dim Authtype

'Set CMS logon credentials - change these to match your particular CE environment
CMS = <@YOURCLUSTER>
Username = "ReadOnly"
Password = "sample123"
Authtype = "secEnterprise"


'Declare variables for Enterprise Session
Dim oEnterpriseSessionMgr
Dim ceSession
Dim iStore
'Get the values
Rid = Request.QueryString("ReportID")
NbrParams = Request.QueryString("NumParens")
If NbrParams > 0 then
ValStr   = Request.QueryString ("Pvals")
NameStr = Request.QueryString ("Pnames")
arrVals = Split(ValStr,";")
arrNames = Split(NameStr,",")
End If


'Load the Enterprise Session Manager

Set oEnterpriseSessionMgr = Server.CreateObject("CrystalEnterprise.SessionMgr")

'Logon to the CMS and create iStore object
Set ceSession = oEnterpriseSessionMgr.Logon(Username, Password, CMS, Authtype)
Set iStore = ceSession.Service("","InfoStore")

'Declare InfoObject Variable
Dim Reports
Dim Report
Dim Qry
'Query the CMS for the report you wish to view
Set Reports = iStore.Query("Select * from CI_InfoObjects Where SI_ProgID = 'CrystalEnterprise.Report' and SI_ID='" & Rid & "'")
Report = Reports.Item(1).Properties("SI_ID")
' Qry = Report.SQLQueryString
'Declare the report parameter variables
Dim reportParameters
Dim fields
Dim tmpParameter
Dim value
Dim NewSpec()
Dim PType()
Dim inx 
Dim pcnt
pcnt = 0
inx = 0

'Get the report parameter(s) using the plugin interface
Set reportParameters = Reports.Item(1).PluginInterface("Report").ReportParameters
If NbrParams > 0 then
                       ' Build an array structure to determine the parameter type
For each parameter in reportParameters
	  pcnt = pcnt + 1
	  Next
	For each parameter in reportParameters
	 ReDim PType(pcnt)
	 PType(inx) = parameter.ValueType
	 inx = inx + 1
	 Next

	'Create a new Fields Collection Object
	Set fields = CreateObject("CrystalReports.Fields")
	
	for n = 0 to (NbrParams - 1)
	' Create a temporary parameter field 
		Set tmpParameter = CreateObject("CrystalReports.ParameterField")
		' Create list of values for this parameter
		arrPvals = Split(arrVals(n),",")
		Max = UBound(arrPvals)
		ReDim NewSpec(Max)
		' Create a parameter value oblect for each value in list 
		for v = 0 to UBound(arrPvals)
		set NewSpec(v)   =  createobject("CrystalReports.ParameterFieldDiscreteValue")  
		Next
		i = 0 ' initialize counter for value list array access
		 for each val in arrPvals  ' assign the value to the parameter
		    if PType(n) = 3 then
		       NewSpec(i).value = cDate(val)
		    else
		         NewSpec(i).value = val
		   end if
		        tmpParameter.CurrentValues.Add NewSpec(i)
		              i = i + 1     ' increment counter
		              		 Next
			 
		tmpParameter.name = arrNames(n)
	Fields.Add tmpParameter
 Next ' parameter
  
End If

'Declare the Report App Factory and Report Document Objects
Dim rptAppFactor
Dim reportDocument

'Create the Report App Factory and Report Document Objects
Set rptAppFactory = iStore.EnterpriseSession.Service("","PSReportFactory")
Set reportDocument = rptAppFactory.OpenReportSource(Report)

[COLOR=red]
'Declare the viewer object variable
Dim Viewer
Set Viewer = CreateObject("CrystalReports.CrystalReportInteractiveViewer")
With Viewer
  .reportSource = reportDocument
  .HasBooleanSearchButton = False
  .HasCrystalLogo = False
  If NbrParams > 0 then
  .ParameterFields = Fields
  End If
  .HasRefreshButton = True
  .IsDisplayGroupTree = False
  .HasPrintButton = true
  .PrintMode = 0 ' disable activeX Printing - set to 1 to enable (may require plug-in is set to 1)
  .IsOwnPage = true
End With
'

Set Session("CES") = ceSession
Set Session("viewer") = Viewer
on error resume next
Viewer.ProcessHTTPRequest Request, Response, Session
[/color]
if err.number <> 0 then
  response.write "Failed to view report" & "</BR>"
  response.write "error number: " & err.number & "</BR>"
  response.write "error description: " & err.description
end if

 

%>
</BODY>
</HTML>

You will need to change to an Export control instead of a viewer control ( The code in red )- see these samples here:

under

ViewersSDK..Developer Guides and SDK reference..Getting Started,..Tutorials..How to Export a Report



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
thank you for the code. I will look into it. I am just curious though how do you get the report id and number of parameters. I see you getting those value using query string...let's us say you have a bunch of report in the folder and how do you get the report id from that folder. can you provide some example. thank you
 
here is what my code looks like. can you look at it and help me where i need to make a change to run the reprot in a pdf format.thank

Code:
Public Class InfoClass
    Public UrlValue As String
    Public RptPars As Object
    Public Rname As String
    Public Urlval As String = ""

    Public Sub New(ByVal rid As String)

        Dim oEnterpriseSessionMgr As Object
        Dim oEnterpriseSession As Object
        Dim InfoStore As Object
        Dim result As Object
        Dim username As String
        Dim password As String
        Dim cms As String
        Dim authType As String
        Dim QueryString As String


        Dim ReportPars As Object
        Dim ReportObject As Object
        Dim ReportInterface As Object

        'Dim OraConn As New OracleConnection
        'Rid = Request.QueryString("ReportID")
        username = "xxx"
        password = "xxx"
        cms = "xxx"
        authType = "xxx"

        'The CreateObject function creates an object of a specified type.
        'CreateObject(servername.typename[,location])
        'Create a session manager.
        oEnterpriseSessionMgr = CreateObject("CrystalEnterprise.SessionMgr")

        oEnterpriseSession = oEnterpriseSessionMgr.Logon(username, password, cms, authType)

        'Create the InfoStore object.
        InfoStore = oEnterpriseSession.Service("", "InfoStore")

        QueryString = "Select SI_ID,SI_NAME,SI_DESCRIPTION,SI_PROCESSINFO.SI_PROMPTS From CI_INFOOBJECTS Where SI_ID =" & rid

        result = InfoStore.Query(QueryString)

        'Retrieve the first report returned.
        ReportObject = result.Item(1)

        'report title/name
        Rname = ReportObject.Title

        ReportInterface = ReportObject.PluginInterface("")

        'ReportParameters:- Contains an ordered list of parameters in the report.# of parameter(s)
        ReportPars = ReportInterface.ReportParameters
        RptPars = ReportPars

    End Sub
    Public Function GetRptName() As String
        Return Rname
    End Function
    Public Function GetPars() As Object
        Return RptPars
    End Function
    Public Function GetUrl() As String
        Urlval = "[URL unfurl="true"]http://xxx/CeViewer/xxx?ReportId="[/URL]
        Return Urlval
    End Function
End Class
 
Hi,
Here is some code you can use to create a drop-down list of reports in a given folder ( pass the FolderID as a query string) and use the attributes of that listing to populate your pages calling URL with the ReportID ( and description, if you wish):
Code:
<script language="VB" runat="server">
'*******************************************************************************************************************************************************
'*
'*
'*                   SECTION 1 - Establish and populate List of reports for supplied folder(ID Passed from URL ) and set Session variables for specific user
'*                               This script section also provides the action function for the button press in the user Secion
'*
'********************************************************************************************************************************************************

Public Cntr As Integer = 1
Public SpecStr As String
Public ErrFlag As Boolean = False
Public NbrPars = 0
Public Sdate,Edate As String
Public Rid As String
If Not Page.IsPostBack Then

Session("Bad") = 0
Rid = Request.QueryString("FolderID")
Uname = Session("Who")
ULevel = Session("Role")
UInst = Session("Inst")
Dim oEnterpriseSessionMgr As Object
Dim oEnterpriseSession As Object
Dim InfoStore As Object
Dim res As Object
Dim res2 As Object
Dim username As String
Dim password As String
Dim cms As String
Dim authType As String
Dim Query As String
Dim RptInfo As Object
Dim FldrInfo As Object
username="ReadOnly"
password="sample123"
cms="@<YOURCMS>"
authType="secEnterprise"

oEnterpriseSession = Session("es")
InfoStore = oEnterpriseSession.Service("","InfoStore")
Query="Select SI_NAME, SI_ID, SI_DESCRIPTION From CI_INFOOBJECTS Where SI_PROGID='CrystalEnterprise.Report' And SI_INSTANCE=0 AND SI_PARENT_FOLDER=" & Rid +	" ORDER BY SI_DESCRIPTION"
Query2="Select SI_NAME, SI_ID, SI_DESCRIPTION From CI_INFOOBJECTS Where SI_ID=" & Rid
res = InfoStore.Query(Query)
res2 = InfoStore.Query(Query2)
RptInfo = res
FldrInfo = res2
Session("TheReports") = RptInfo      
Dim Fldrs As Object = FldrInfo   
Dim FldrName = Fldrs.Item(1).Description
Label5.Text = FldrName
dim list1=New SortedList     'Create display list items ( ReportID and Report Name )
For Cntr = 1 To Session("TheReports").Count
  list1.Add(Session("TheReports").Item(Cntr).ID,Session("TheReports").Item(Cntr).Title)
Next  
  rpts.DataSource=list1
  rpts.DataValueField="Key"
  rpts.DataTextField="Value"
  rpts.DataBind()
  rpts.SelectedIndex = 0
  InfoStore=Nothing    'Clear connection to BOE
  End If

End Sub

Sub ShowChoice(sender As Object, e As EventArgs)       'Button press activates this action
Dim RunReport = "[i]<YOURPAGEWITHCPDE>.aspx?ReportID=" & rpts.SelectedItem.Value[/i]
Response.Redirect(RunReport)

 End Sub

'*********************************************************************************************************************
'*
'*             END OF SECTION ONE
'*
'*********************************************************************************************************************

</script>

</head>
<body>

<div id="template_main_content">
<a name="main"></a>
      <!-- ###################################################################### -->
      <!-- Begin user area  -->
       <!--     CREATES THE ASP.NET LISTBOX CONTROL THAT USES THE DATASET CREATED IN SECTION 1 TO LIST THE REPORTS AND SETS UP THE CLICKABLE BUTTON TO PROCEED TO THE NEXT PAGE -->
      <!-- ###################################################################### -->
	<form runat="server">
		
		
	      <table border=0 width=615 cellspacing=1 cellpadding=0>
	      <th class='heading'>
	      	<asp:Label id="Label5" runat="server" /> <TR><TD class='heading'> Select Report to Run  </B></th>
      
      <tr>
     	 <TD class='heading'>

     <%
     'Test comment line'
     %>       	               	        
   <asp:ListBox id="rpts" runat="server" Style="width:450px;font-size:18px;color:#AA0000;"  Rows="15" >
              	        </asp:ListBox>   
              	  </TR><TR><TD class='dropdown'>
              	 <button id="Button1"
              OnServerClick="ShowChoice"
              runat="server">
    Get Parameters
    </button></td>
    	  </TABLE>
        	   	        
  </form>
    <!-- ###################################################################### -->
            <!-- End user area  -->
  <!-- ###################################################################### -->
          

</div>

As for where to use the code for PDF export like in the site's examples I posted, I would need to know the code on the pages in this code ://xxx/CeViewer/xxx to see how you are actually using the PVALS, etc before calling the report.




[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
you can export to pdf programmaticaly without the crystal report viewer. I don't think (at least not easily) a way to limit the options available in the crystal report viewer.

the easiest thing would be to use a 3rd party js library like jquery to alter the html of the report viewer. use jquery to remove all export options except pdf.

there is plenty of help online about javascript and specific 3rd party libraries. If you peruse this route think of jquery modifying the html, not modifying a crystal report viewer. after all a CRV is just a server control to render html like any other server control.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top