Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I want to do a batch Convert of all Crystal Report files into PDF

Posted on 2004-10-21
12
Medium Priority
?
823 Views
Last Modified: 2009-05-06
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.DiskFileName = "c:\pdf_report.pdf"
        rep.ExportOptions.DestinationType = crEDTDiskFile
        rep.ExportOptions.FormatType = crEFTPortableDocFormat
        rep.Export(False)
    End Sub

Please help?  Thanks ahead of time vikingg97
0
Comment
Question by:vikingg97
[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
  • 7
  • 5
12 Comments
 
LVL 42

Expert Comment

by:frodoman
ID: 12371959
Have you added the crystal references to your project - sounds like you haven't so CRAXDRT isn't going to be recognized.

frodoman
0
 
LVL 42

Expert Comment

by:frodoman
ID: 12371987
Actually I looked again at your code - try this:

Dim appl As CRAXDRT.Application
Dim rep As CRAXDRT.report
       
Set appl = CreateObject("CrystalRuntime.Application.9")
Set rep = appl.OpenReport("c:\mytest.rpt",1)

frodoman
0
 
LVL 1

Author Comment

by:vikingg97
ID: 12372243
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("CrystalRuntime.Application.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.
0
Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

 
LVL 42

Expert Comment

by:frodoman
ID: 12372649
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.CrystalReports.Engine
Imports CrystalDecisions.Shared


Dim CrReport As New CrystalReport1()
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions as New PdfRtfWordFormatOptions()

'Set the destination path and file name
CrDiskFileDestinationOptions.DiskFileName = "c:\RichText.pdf"

'Specify a page range (optional)
crFormatTypeOptions.FirstPageNumber = 1
crFormatTypeOptions.LastPageNumber = 3
crFormatTypeOptions.UsePageRange = True

'Set export options
CrExportOptions = crReport.ExportOptions

With CrExportOptions
'Set the destination to a disk file
.ExportDestinationType = ExportDestinationType.DiskFile
'Set the format to PDF
.ExportFormatType = ExportFormatType.PortableDocFormat
'Set the destination options to DiskFileDestinationOptions object
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = crFormatTypeOptions
End With

' Trap any errors that occur on export
Try
'Export the report
CrReport.Export()
Catch err As Exception
MessageBox.Show(err.ToString())
End Try

This code from here: http://support.businessobjects.com/library/kbase/articles/c2010264.asp

frodoman
0
 
LVL 1

Author Comment

by:vikingg97
ID: 12373807
Ok I have done this and come up with the squigly lines under  CrystalDecisions.CrystalReports.Engine and CrystalDecisions.Shared
for these lines
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared


Here is what the tooltip says:
--namespace for type engine for the imports of 'CrystalDecisions.CrystalReports.Engine' cannot be found.

--namespace for type engine for the imports of 'CrystalDecisions.Shared' cannot be found.
0
 
LVL 42

Expert Comment

by:frodoman
ID: 12373928
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
0
 
LVL 1

Author Comment

by:vikingg97
ID: 12374140
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.ToString())  ''*MessageBox is not Declared

I think I am getting closer..
0
 
LVL 42

Expert Comment

by:frodoman
ID: 12374307
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.

0
 
LVL 42

Expert Comment

by:frodoman
ID: 12374354
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.
0
 
LVL 1

Author Comment

by:vikingg97
ID: 12380507
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.
0
 
LVL 42

Accepted Solution

by:
frodoman earned 2000 total points
ID: 12380598
Basically what you'll want to do is take your working export code and put it inside a loop that itterates through all of the files.  You'll have to flesh this out a little bit but the basic process would be something like this:


    Dim fileList() As String = System.IO.Directory.GetFiles(pathSource)
    For Each fileSource As String In fileList
        If  Right(fileSource,4) = ".rpt" Then
           <<<Crystal Export Code Here>>>
        End If
    Next

In your crystal export code replace the hard coded filename with the "fileSource" variable.  If you need additional help with the looping you should probably post a separate question in the VB.Net forum ( http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/ ).

HTH

frodoman
0
 
LVL 1

Author Comment

by:vikingg97
ID: 12381879
Thanks frodoman, I posted a new question on VB.NET still relating to this question on http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21177464.html 

If anyone needs to follow this.  

Thanks again frodoman.

vikingg97
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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. …
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

610 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