VB 6.0 Crystal Reports Export to PDF - vb.net

I'm having issues with reporting a Crystal Reports file to PDF format. I've looked at all the other questions here regarding the issue but none of them seem to solve mine.
Here is my code:
Public Sub ExportReportToPDF(ReportObject As CRAXDRT.Report, ByVal filename As String, ByVal ReportTitle As String)
Dim objExportOptions As CRAXDRT.ExportOptions
ReportObject.ReportTitle = ReportTitle
With ReportObject
.EnableParameterPrompting = False
.MorePrintEngineErrorMessages = True
End With
Set objExportOptions = ReportObject.ExportOptions
With objExportOptions
.DestinationType = crEDTDiskFile
.DiskFileName = filename
'.FormatType = crEFTExcel80Tabular
'.FormatType = crEFTCommaSeparatedValues
'.FormatType = crEFTExcel80
'.FormatType = crEFTHTML32Standard
'.FormatType = crEFTHTML40
.FormatType = crEFTPortableDocFormat
'.FormatType = crEFTRichText
'.FormatType = crEFTText
'.FormatType = crEFTWordForWindows
End With
ReportObject.Export False
End Sub
Now, I've left the other options besides PDF in there just to show them, they're all commented out obviously, but if I try any of the other formats, it exports just fine. The only format that doesn't export is PDF. It gives me the error:
Run-time error '-2147190908 (80047784)':
Failed to Export the Report.
When I click Debug it highlights on the ReportObject.Export False line.
On another note, if I make it so the user chooses the options, I can select PDF and it still gives me the same error. Thanks for the help.
(Thanks to AVD for the coding found here How to Export to a PDF file in Crystal Report?).
EDIT: After going through Phillipe's responses, I was stepping through my code and noticed that after it assigned crEFTPortableDocFormat to FormatType, it auto assigns "UXFPDF.DLL" to FormatDllName. Maybe this is my problem, does anyone know how to fix this? I tried just renaming crxf_pdf.dll and also u2fpdf.dll (the one that was for 8.0 which I originally had) but that didn't work.
EDIT: Another find is that when I enable the Export Option in CRViewer91 (which shows the report correctly) and I try and export this to a pdf via this method, it does not error. However, it saves a file that is corrupted pretty much and cannot be opened.
EDIT: More research. The CRViewer91 doesn't appear to be able to export any format successfully. RTF and TXT return a blank document, RPT errors when trying to open.
EDIT: I think part of my problem may be that I've been using the 8.0 CRAXRT.DLL when what I actually need is the 9.0 one. I've found the one for 9.0, now how do I make it use this instead of the old one?

I'm not exactly sure what was causing all the errors, however, I've fixed it via basically starting a new project from scratch and incorporating only the necessary references and components. I know one problem I had (which caused a TLV error) was that the CRAXDRT.dll for CR9 was in the Windows\system32 directory, and even though it was referencing that .dll, it needed to reference it from the Program Files\Common Files\CrystalDecision... directory where all the other .dlls for CR9 are located.
There was also a minor code change that needed to be done, here is the finalized code that works for exporting mine to PDF.
Public Sub ExportReportToPDF(ReportObject As CRAXDRT.Report, ByVal filename As String, ByVal ReportTitle As String)
Dim FormatDLLName As String
ReportObject.ReportTitle = ReportTitle
With ReportObject
.EnableParameterPrompting = False
.MorePrintEngineErrorMessages = True
End With
With ReportObject.ExportOptions
.DestinationType = crEDTDiskFile
.DiskFileName = filename
'.FormatType = crEFTExcel80Tabular
'.FormatType = crEFTCommaSeparatedValues
'.FormatType = crEFTExcel80
'.FormatType = crEFTHTML32Standard
'.FormatType = crEFTHTML40
.FormatType = crEFTPortableDocFormat
'.FormatType = crEFTRichText
'.FormatType = crEFTText
'.FormatType = crEFTWordForWindows
End With
ReportObject.Export False
End Sub
I left the commented out FormatTypes in there for anyone else who finds this code useful. Phillipe, if you would like to "answer" this somehow like this, I would love to give you some rep for all of your help that you provided however. I don't have enough rep to just upvote your stuff so.
Thanks for all your help either way.
Dan

I guess that 'filename' value does not work, either because the folder does not exist / the file name is not valid, or because you do not have the corresponding rights to create a file under this folder.
Could you try the code with some basic parameter like 'filename = "c:\test.pdf"'?
My last guess: the possibility to export to pdf format needs a specific dll file under the crystal folder (does not need to be registered but needs to be here). Do you have the crxf_pdf.dll file ?
EDIT:
My last question: are you able to expor tto PDF from the Crystal GUI?
Here is a list of the crystal report files that must be distributed with a VB app, if of any help: export capabilities seem to be linked to the crxf_*.dll files
CRAnalyzer.dll
craxdrt.dll
crdb_ado.dll
crdeploy.reg
crheapalloc.dll
crqe.dll
crtowords_en.dll
crtslv.dll
crviewer.dll
crxf_html.dll
crxf_pdf.dll
crxf_rtf.dll
crxf_wordw.dll
crxf_xls.dll
cxlibw-1-6.dll
dbghelp.dll
exlate32.dll
ExportModeller.dll
GDIPLUS.DLL
Implode.dll
keycode.dll
msvcrt.dll
pageObjectModel.dll
querybuilder.dll
ReportRenderer.dll
riched20.dll
sscdlg.dll
sscsdk80.dll
u252000.dll
u25dts.dll
u25samp1.dll
u2dapp.dll
u2ddisk.dll
u2dmapi.dll
u2dpost.dll
u2fcr.dll
u2frdef.dll
u2frec.dll
u2fsepv.dll
u2ftext.dll
u2fxml.dll
u2l2000.dll
u2lcom.dll
u2ldts.dll
u2lexch.dll
u2lfinra.dll
ufmanager.dll
usp10.dll
webReporting.dll

Related

VBA replace logo in Excel file

I have a little strange question. I used to have few reports worked upon daily.
All these are in Excel and had a logo of the company in all the sheets of each file.
However, now the company name is changed and hence a new logo needs to be replaced in place of the existing. Wanted to check if this replacement can be done with VBA.
I tried with the application.shapes method. But, was confused to proceed further.
Try this....
Sub ChangePicture(strNewPath As String)
Dim oOld As Picture
Dim oNew As Picture
Set oOld = ActiveSheet.Pictures(1)
Set oNew = ActiveSheet.Pictures.Insert(strNewPath)
oNew.Left = oOld.Left
oNew.Top = oOld.Top
oNew.Width = oOld.Width
oNew.Height = oOld.Height
oOld.Delete
End Sub

ActiveReports not allowing overwrite of jpg after report generation. Windows. VB.NET

Currently, I am utilizing ActiveReports to implement a dynamic image via pathname into a report that is generating.
The Images are being automatically generated as .jpg to a server folder. The Active Reports module imports the files using this code.
Sub ActiveReport_ReportStart
Picture1.Image = System.Drawing.Image.FromFile("path\filename.jpg")
End Sub
The problem I am running into is that this report locks out the jpgs from being overwritten.
I am unsure what could be going wrong, but it seems that the report is still using the image files after the report has been generated.
Am I missing a "disconnect" code piece to ensure that an import doesn't allow for continued contact to the file?
I apologize if this is simple, but I can't find anything for this specific instance.
Thank you.
EDIT:
I attempted to get around the lockout by copying them into their own variable. But this didn't work either.
Sub ActiveReport_ReportStart
dim TempImage as Image = Image.FromFile("path\filename")
Picture1.Image = TempImage
End Sub
You can use "Using" block to make sure that the object of the image is disposed as soon as its usage is completed.
Using statement basically marks a boundary for the objects specified in the statement. So when code block using Using – End Using is exited either after normal execution or some exception cause, the framework invokes the Dispose method of these objects automatically.
Here is the suggested code which can be helpful for you in resolving the issue:
Private Sub SectionReport1_ReportStart(sender As Object, e As EventArgs) Handles MyBase.ReportStart
Dim img As Image
Using bmpTemp = New Bitmap("path\filename.jpg")
img = New Bitmap(bmpTemp)
End Using
Picture1.Image = img
End Sub
I was able to get this to work by creating a function that used the Graphics.FromImage method and disposed the original file.
Public Function GetImageFile(ByVal pathfn As String) As Image
Dim tempImg As Image = Image.FromFile(pathfn)
Dim tempBtm As New Bitmap(Width:=img.Width*CorrectFactor, Height:=img.Height*CorrectFactor, Format:=tempImg.PixelFormat)
Using g As Graphics = Graphics.FromImage(bm)
g.DrawImage(tempImg, Point.Empty)
End Using
tempImg.Dispose()
Return tempBtm
End Function
The item that would be placed in the report would be as follows.
Sub ActiveReport_ReportStart
Picture1.Image = GetImageFile("Path\Filename")
End Sub

XML Reader Variables VB.NET

Working on a management program for basic files and text.
Now, so far the program is saving information from multiple textboxes into an .xml file correctly.
My problem is where I need to load saved files back into Textboxes.
Here is another thread I made to Microsoft explaining my issue;
Right, so the code I currently have and use;
Private Sub Objectlist1_ItemActivate(sender As Object, e As EventArgs) Handles Objectlist1.ItemActivate
Caseworker.Show()
Me.Objectlist1.MultiSelect = False
Dim selectedListViewItem As String
selectedListViewItem = Me.Objectlist1.SelectedItems.Item(0).ToString
If (IO.File.Exists(selectedListViewItem + "C:\Users\USER\Desktop\Testfolder-data")) Then
Dim document As XmlReader = New XmlTextReader(selectedListViewItem + "C:\Users\USER\Desktop\Testfolder-data")
While (document.Read())
Dim type = document.NodeType
If (type = XmlNodeType.Element) Then
If (document.Name = "Person") Then
Caseworker.Pholderbox.Text = document.ReadInnerXml.ToString()
End If
If (document.Name = "Driver") Then
Caseworker.Driverbox.Text = document.ReadInnerXml.ToString()
Problem here is that I want to be able to click a file in the Listview called "Objectlist1" and the program loads the xml file - Instead of directing the program to One file
As such
If (IO.File.Exists("MyXML.xml")) Then
Dim document As XmlReader = New XmlTextReader("MyXML.xml)
Apparently there is this variable out there that would be perfect for my issue, but I have looked for it for 2 working days and not been able to track it down.
If there is another stuff I need to add to make this thing work, I appreciate any help you can provide.
Am I far off here guys?
A few things:
You need the full path to the XMLFile, not just its name. You could do it like this (warning: untested):
const string basepath= #"C:\Users\USER\Desktop\Testfolder-data"
xmlpath = IO.Path.Combine(basepath, Objectlist1.SelectedItems.Item(0).Text)
If(IO.File.Exists(xmlpath))
Instead of multiple Ifs, I would recommend
switch(document.Name)
{
Case "Person":
Caseworker.Pholderbox.Text=...
break;
Case "Driver":
...
}
If you rename "Pholderbox" to "Personbox", you could spare the entire If/switch and simply do something like:
var textbox = document.name + "box";
(TextBox)Caseworker.Controls[textbox].Text=document.InnerText;
Hope this gets you going.

Using Spire.PDF to merge pdf files Errors

I am using the free licenced version of Spire PDF. My program has in the region of 166,ooo pdf files which represent individual pages. I need to merge between 1 and 20 of these with the same names into one pdf.
I have a routine the builds a string of filenames to be added to an array which is passed to the following sub as PDFFiles. The OutputFile is the string with the name of the output file with it's path.
Private Sub MergePDFs(ByVal PDFFiles As String, ByVal OutPutFile As String)
Dim files As [String]() = New [String]() {"E:\Ballads of the 20th Century\1st bari #1.pdf", "E:\Ballads of the 20th Century\1st bari #2.pdf"}
Dim i As Integer
'open pdf documents
Dim docs As PdfDocument() = New PdfDocument(files.Length - 1) {}
For i = 0 To files.Length - 1
docs(i) = New PdfDocument(files(i))
Next
'append document
docs(0).AppendPage(docs(1))
'import PDF pages
i = 0
While i < docs(2).Pages.Count
docs(0).InsertPage(docs(2), i)
i = i + 2
End While
End Sub
I have the Solution Explorer I have the Spire.Pdf.dll as a file. In References I have Spire.Pdf and Spire.Licence.
At runtime I get An unhandled exception of type 'System.ArgumentException' occurred in Spire.Pdf.dll
Additional information: File doesn't exist.
The PDFFiles is not used in this example for clarity. The two files listed are taken directly from the program output for testing purposes.
There has to be a simple explanation for this error, but I haven't found one yet.
Please can you help solve it.
Thanks
Graham
I found the answer to this myself.
The actual problem was the way Spire.pdf parses a string into a pdf document.
There must be no spaces in the filename, then it works fine.
Graham

How do you load an image from resource file in vb 2010 expresss?

First of all Im new to vb 2010 and so far have enjoyed what I have been able to do with it. That being said I have run into an issue with my current project.
Basically I have created a timer and all works well on that part. My issue lies in that my timer loads a .png for each minute/second and I was linking the images like so:
Picturebox1.Image = Image.Fromfile("C:\timer\images\" & minutes.text & ".png")
Picturebox2.Image = Image.Fromfile("C:\timer\images\" & seconds.text & ".png")
So running this on another pc rendered that bit of code useless as that computer did not have those files locally and the program would end in an error as it could not find the .png files.
I did a bit of searching online and found a few sites and video tutorials how to read from the resource file. But in doing so I have been unable to make it function properly.
So this is what I found here:
Picturebox1.image = My.Resources.minutes.text
Picturebox2.image = My.Resources.seconds.text
I know this bit of code is wrong as I'm now getting 2 errors in vb 2010. The only way I have managed to make this work is to specify the file name. But what I'm wanting to do is use whats in "minutes.text" and "seconds.text" to specify the file name.
Is there a way around this? or do I have to use a bunch of if statements to do this?
example:
If minutes.text = 1 Then
picturebox1 = My.Resource._1
End If
If seconds.text = 12 Then
Picturebox2 = My.Resource._12
End If
I would hate having to do a bunch of if statements if there is a simple fix. So I've come here for help.
i think you are looking for this:
Dim currentMin as string = "_" & minutes.text ' it would look something like this: _1
picturebox1.Image = CType(My.Resources.ResourceManager.GetObject(currentMin), Image)
Dim currentSec as string = "_" & seconds.text
picturebox2.Image = CType(My.Resources.ResourceManager.GetObject(currentSec), Image)
I have tried this form, and it is functional
Picturebox1.Image = Image.FromHbitmap(My.Resources.imagename.GetHbitmap())