vikingg97
asked on
I want to do a batch Convert of all Crystal Report files into PDF
Basically I want to convert every crystal report file (.rpt) that is in a certain folder into a pdf. I set up a VB.NET Windows form for a button click to just try with one report first, then eventually I want change to loop through all records when I can get this one working.
Would this be the correct way to do it? Errors it shows for me are
CRAXDRT.Application is not defined
CRAXDRT.Report is not defined
crEDTDiskFile is not declared
crEFTPortableDocFormat is not declared
Here is the code.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Transformation.Click
Dim appl As New CRAXDRT.Application
Dim rep As CRAXDRT.Report
rep = appl.OpenReport("c:\mytest .rpt", 1)
rep.ExportOptions.DiskFile Name = "c:\pdf_report.pdf"
rep.ExportOptions.Destinat ionType = crEDTDiskFile
rep.ExportOptions.FormatTy pe = crEFTPortableDocFormat
rep.Export(False)
End Sub
Please help? Thanks ahead of time vikingg97
Would this be the correct way to do it? Errors it shows for me are
CRAXDRT.Application is not defined
CRAXDRT.Report is not defined
crEDTDiskFile is not declared
crEFTPortableDocFormat is not declared
Here is the code.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Transformation.Click
Dim appl As New CRAXDRT.Application
Dim rep As CRAXDRT.Report
rep = appl.OpenReport("c:\mytest
rep.ExportOptions.DiskFile
rep.ExportOptions.Destinat
rep.ExportOptions.FormatTy
rep.Export(False)
End Sub
Please help? Thanks ahead of time vikingg97
Actually I looked again at your code - try this:
Dim appl As CRAXDRT.Application
Dim rep As CRAXDRT.report
Set appl = CreateObject("CrystalRunti me.Applica tion.9")
Set rep = appl.OpenReport("c:\mytest .rpt",1)
frodoman
Dim appl As CRAXDRT.Application
Dim rep As CRAXDRT.report
Set appl = CreateObject("CrystalRunti
Set rep = appl.OpenReport("c:\mytest
frodoman
ASKER
How do I add the crystal references to your project?
Also I added:
Dim appl As CRAXDRT.Application -->STILL saying not defined
Dim rep As CRAXDRT.report -->STILL saying not defined
Set appl = CreateObject("CrystalRunti me.Applica tion.9")
Set rep = appl.OpenReport("c:\mytest .rpt",1)
Also it won't let me write Set on VS.NET? It just corrects it like its not supposed to be there. Any clue?
Sorry about the loaded questions.
Also I added:
Dim appl As CRAXDRT.Application -->STILL saying not defined
Dim rep As CRAXDRT.report -->STILL saying not defined
Set appl = CreateObject("CrystalRunti
Set rep = appl.OpenReport("c:\mytest
Also it won't let me write Set on VS.NET? It just corrects it like its not supposed to be there. Any clue?
Sorry about the loaded questions.
I always do that - too much asp work lately. Forget the 'set' keywork.
Actually you should probably just scrap what you've got and go with code like this:
Imports CrystalDecisions.CrystalRe ports.Engi ne
Imports CrystalDecisions.Shared
Dim CrReport As New CrystalReport1()
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptio ns As New DiskFileDestinationOptions ()
Dim CrFormatTypeOptions as New PdfRtfWordFormatOptions()
'Set the destination path and file name
CrDiskFileDestinationOptio ns.DiskFil eName = "c:\RichText.pdf"
'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()
Catch err As Exception
MessageBox.Show(err.ToStri ng())
End Try
This code from here: http://support.businessobjects.com/library/kbase/articles/c2010264.asp
frodoman
Actually you should probably just scrap what you've got and go with code like this:
Imports CrystalDecisions.CrystalRe
Imports CrystalDecisions.Shared
Dim CrReport As New CrystalReport1()
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptio
Dim CrFormatTypeOptions as New PdfRtfWordFormatOptions()
'Set the destination path and file name
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()
Catch err As Exception
MessageBox.Show(err.ToStri
End Try
This code from here: http://support.businessobjects.com/library/kbase/articles/c2010264.asp
frodoman
ASKER
Ok I have done this and come up with the squigly lines under CrystalDecisions.CrystalRe ports.Engi ne and CrystalDecisions.Shared
for these lines
Imports CrystalDecisions.CrystalRe ports.Engi ne
Imports CrystalDecisions.Shared
Here is what the tooltip says:
--namespace for type engine for the imports of 'CrystalDecisions.CrystalR eports.Eng ine' cannot be found.
--namespace for type engine for the imports of 'CrystalDecisions.Shared' cannot be found.
for these lines
Imports CrystalDecisions.CrystalRe
Imports CrystalDecisions.Shared
Here is what the tooltip says:
--namespace for type engine for the imports of 'CrystalDecisions.CrystalR
--namespace for type engine for the imports of 'CrystalDecisions.Shared' cannot be found.
In your solution explorer, expand to the "References" node and right click then select Add Reference. You should see CrystalDecisions.Shared under the .Net tab - select it, then select the CrystalReports.Engine and click OK. This will add these dll's to your project.
frodoman
frodoman
ASKER
Ok added the references to it and squiglies are gone but new ones appear on
Dim CrReport As New CrystalReport1 ''* Error CrystalReport1 is not defined
MessageBox.Show(err.ToStri ng()) ''*MessageBox is not Declared
I think I am getting closer..
Dim CrReport As New CrystalReport1 ''* Error CrystalReport1 is not defined
MessageBox.Show(err.ToStri
I think I am getting closer..
Don't worry about the messagebox for now - that's just error trapping code anyway.
CyrstalReport1 is the name of the viewer. You should drag a viewer from your toolbox onto your form. By default it'll be named CrystalReport1 - of course you can change the name and just change your code to reflect whatever name you use.
CyrstalReport1 is the name of the viewer. You should drag a viewer from your toolbox onto your form. By default it'll be named CrystalReport1 - of course you can change the name and just change your code to reflect whatever name you use.
Ignore the last post - my brain is hurting today. Instead:
Rt-click on your project then select Add -> Add New Item -> Crystal Report.
This will add a report object to your project and create the class which will be named (by default) CrystalReport1.
Rt-click on your project then select Add -> Add New Item -> Crystal Report.
This will add a report object to your project and create the class which will be named (by default) CrystalReport1.
ASKER
OK cool that is happening for me now and it builds just fine creating my pdf. Thanks frodoman. I will award you the points, but for the most part I am wanting to look out in a certain folder for CR, and loop through it to generate pdf's for all of them, in one button click. I am not sure if I should post this as a new question, for more points or not, let me know. If someone else can answer this, then I can award partial points, since frodo mostly helped me. Let me know frodoman..
Thanks in advance.
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks frodoman, I posted a new question on VB.NET still relating to this question on https://www.experts-exchange.com/questions/21177464/I-want-to-do-a-batch-Convert-of-all-Crystal-Report-files-into-PDF.html
If anyone needs to follow this.
Thanks again frodoman.
vikingg97
If anyone needs to follow this.
Thanks again frodoman.
vikingg97
frodoman