vikingg97
asked on
Batch of CRYSTAL REPORTS into PDF with Parameters
I have a batch process that gets Crystal reports out of a certain folder that turns them into PDF's without parameters and now I have CR that need to have parameters fed into them.
They could be all different types of parameters, including ones with multiple parameters. I need to be able to feed the parameters into different reports doing a batch process that runs.
I am guessing I would use a table to feed these into CR? I am using VB.NET This is an extention of another question which here is the code. Thanks ahead of time vikingg97
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalRe ports.Engi ne
Imports CrystalDecisions.Shared
Imports System.IO
Imports Microsoft.VisualBasic
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Butto n
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Butto n
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(256, 32)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(144, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Generate PDF from CR"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 461)
Me.Controls.Add(Me.Button1 )
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Place the following name spaces at the top of the code page
Dim fileList() As String = System.IO.Directory.GetFil es("c:\ine tpub\wwwro ot\MCNETWe bSite\IT_W ork\")
For Each fileSource As String In fileList
'Microsoft.VisualBasic.Get Object("C: \WindowsAp p\WindowsA pplication 1\error.rp t")
'MessageBox.Show(uu)
If Strings.Right(fileSource, 4) = ".rpt" Then
'Crystal Export Code Here
Dim CrReport As New ReportDocument
CrReport.Load(fileSource, OpenReportMethod.OpenRepor tByDefault )
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptio ns As New DiskFileDestinationOptions
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions
' Set the destination path and file name
' 41 is the spot where I need to get file name 41 (34 old)
Dim mid As String
mid = Strings.Mid(fileSource, 41)
' Gets the length of the filename
Dim LengthObjName As String
LengthObjName = Strings.Len(mid)
' Gets charactor to start at for taking out of the .rpt
Dim LengthFrom_rpt As String
LengthObjName = CInt(LengthObjName - 4)
' Gets the actual file name minus the .rpt extension
Dim strVarName As String
strVarName = Strings.Left(mid, LengthObjName)
'Getobj = Microsoft.VisualBasic.GetO bject(file Source)
Dim pdf_path As String
pdf_path = "c:\CR_Convert_to_PDF\" & strVarName & ".pdf"
CrDiskFileDestinationOptio ns.DiskFil eName = pdf_path
'Specify a page range (optional)
CrFormatTypeOptions.FirstP ageNumber = 1
CrFormatTypeOptions.LastPa geNumber = 3
CrFormatTypeOptions.UsePag eRange = True
'Set export options
CrExportOptions = CrReport.ExportOptions
With CrExportOptions
'Set the destination to a disk file
.ExportDestinationType = ExportDestinationType.Disk File
'Set the format to PDF
.ExportFormatType = ExportFormatType.PortableD ocFormat
'Set the destination options to DiskFileDestinationOptions object
.DestinationOptions = CrDiskFileDestinationOptio ns
.FormatOptions = CrFormatTypeOptions
End With
' Trap any errors that occur on export
Try
'Export the report
CrReport.Export()
MessageBox.Show("PDF File Generated from " & fileSource & " into location: " & pdf_path)
Catch err As Exception
MessageBox.Show(err.ToStri ng())
End Try
End If
Next
MessageBox.Show("All pdf files created successfully.")
End Sub
End Class
They could be all different types of parameters, including ones with multiple parameters. I need to be able to feed the parameters into different reports doing a batch process that runs.
I am guessing I would use a table to feed these into CR? I am using VB.NET This is an extention of another question which here is the code. Thanks ahead of time vikingg97
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalRe
Imports CrystalDecisions.Shared
Imports System.IO
Imports Microsoft.VisualBasic
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Butto
<System.Diagnostics.Debugg
Me.Button1 = New System.Windows.Forms.Butto
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(256, 32)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(144, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Generate PDF from CR"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 461)
Me.Controls.Add(Me.Button1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Place the following name spaces at the top of the code page
Dim fileList() As String = System.IO.Directory.GetFil
For Each fileSource As String In fileList
'Microsoft.VisualBasic.Get
'MessageBox.Show(uu)
If Strings.Right(fileSource, 4) = ".rpt" Then
'Crystal Export Code Here
Dim CrReport As New ReportDocument
CrReport.Load(fileSource, OpenReportMethod.OpenRepor
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptio
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions
' Set the destination path and file name
' 41 is the spot where I need to get file name 41 (34 old)
Dim mid As String
mid = Strings.Mid(fileSource, 41)
' Gets the length of the filename
Dim LengthObjName As String
LengthObjName = Strings.Len(mid)
' Gets charactor to start at for taking out of the .rpt
Dim LengthFrom_rpt As String
LengthObjName = CInt(LengthObjName - 4)
' Gets the actual file name minus the .rpt extension
Dim strVarName As String
strVarName = Strings.Left(mid, LengthObjName)
'Getobj = Microsoft.VisualBasic.GetO
Dim pdf_path As String
pdf_path = "c:\CR_Convert_to_PDF\" & strVarName & ".pdf"
CrDiskFileDestinationOptio
'Specify a page range (optional)
CrFormatTypeOptions.FirstP
CrFormatTypeOptions.LastPa
CrFormatTypeOptions.UsePag
'Set export options
CrExportOptions = CrReport.ExportOptions
With CrExportOptions
'Set the destination to a disk file
.ExportDestinationType = ExportDestinationType.Disk
'Set the format to PDF
.ExportFormatType = ExportFormatType.PortableD
'Set the destination options to DiskFileDestinationOptions
.DestinationOptions = CrDiskFileDestinationOptio
.FormatOptions = CrFormatTypeOptions
End With
' Trap any errors that occur on export
Try
'Export the report
CrReport.Export()
MessageBox.Show("PDF File Generated from " & fileSource & " into location: " & pdf_path)
Catch err As Exception
MessageBox.Show(err.ToStri
End Try
End If
Next
MessageBox.Show("All pdf files created successfully.")
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The things you are asking has to be done by the application. You have to write and deploy an application. The application has to set the parameters runtime to the report , then display the report to the user. If you dont want the user t osee the report then you can directly send it to the exporting module.
It is not so easy to write this application. First you have to decide what language is available t oyou. What version of crystal do you have and how much does it let you make ru time customizations. Maybe after answering these questions, you will see that you wont be able to do it with your current version and need to uprade
It is not so easy to write this application. First you have to decide what language is available t oyou. What version of crystal do you have and how much does it let you make ru time customizations. Maybe after answering these questions, you will see that you wont be able to do it with your current version and need to uprade
ASKER
I have all the latest technologies available, using CR 10 and VB.NET through VS.NET. I have already written this application to export the CR to PDF. This works with a basic crystal report with no parameters pushed in. I am just wanting to pass parameters into reports then have it convert to a pdf.
If you can just help me get this done, for example with say 2 reports with parameters, then that is for the most part what I need. I posted the code above with the working process converting CR into pdf. Lets say I want a parameter of date and plancode on one report and name and version on the second report.
Thanks vikingg97
If you can just help me get this done, for example with say 2 reports with parameters, then that is for the most part what I need. I posted the code above with the working process converting CR into pdf. Lets say I want a parameter of date and plancode on one report and name and version on the second report.
Thanks vikingg97
That is perfect hope you are using c#. The code I posted is C# for parameters. Use that you will be good to go. If you dont undrstand anythind ask me. It works because I have the same technologies and doing it right now
Good luck brother
Emre
Good luck brother
Emre
ASKER
Like I said I am not using C#, I am using VB.NET. So the C# code you have posted isn't helping this vb.net beginner.
I said before that if someone could maybe show me an example in VB.NET and just help me get this started, for example with say 2 reports with parameters, then that is for the most part what I need. I posted the code above with the working process converting simnple CR into pdf. Lets say I want a parameter of date and plancode on one report and name and version on the second report.
If someone could help with that part of it just going through 2 reports with those parameters with the code I have already posted, I would appreciate it VERY MUCH. This is kinda urgent.
I said before that if someone could maybe show me an example in VB.NET and just help me get this started, for example with say 2 reports with parameters, then that is for the most part what I need. I posted the code above with the working process converting simnple CR into pdf. Lets say I want a parameter of date and plancode on one report and name and version on the second report.
If someone could help with that part of it just going through 2 reports with those parameters with the code I have already posted, I would appreciate it VERY MUCH. This is kinda urgent.
ASKER
ANYONE? Help please?
I dont have time to convert the code to vb.net. It is very similar though. And that code works because I am using in 100 reports.
ASKER
So that snippet you added works for converting CR to PDF with any multitude of parameters?
that code sets the parameters of the report in runtime
You have to write little bit more to export t opdf as well.
You have to write little bit more to export t opdf as well.
Glad I could help
Regards
Emre
Regards
Emre
ASKER
Unsure what you mean on
--1. Set the parameters to the report document runtime
--2. Get the full report
Also I don't know what you mean about what you mean about knowing the object model and how long it is, and setting the report document as the viewers datasource crystalviewer1.reportsourc
I don't want to even see the reports while its processing, I just want them to all to export from in a certain folder feeding parameters making a PDF.
once again I appreciate ahead of time. vikingg97