| How to print Picture in Crystal Report 8.5 |
| Atheeq Ahmed posted at Monday, June 16, 2008 12:44 AM |
Dear Friends,
Please help how to print picture in Crystal Report 8.5 from the given path
e.g :
Sqlserver 2000
Records Like
Mr. George Executive D:\foto\george.jpg
Mr. John Asst.Manager D:\foto\John.jpg
Pls help in this regards.
Atheeq
|
 |
|
|
| |
Here is the code to print picture in crystal report |
| Sujit Patil replied to Atheeq Ahmed at Monday, June 16, 2008 1:06 AM |
Just create a temp table add a oleObject(bolb field) place the image u want to show in report after report generation delete that file I am sending code in which i used chunck table to show the picture
i mapped that feild in report.
Public Sub SaveReportPicture(rtfOrig As RichTextBox, rtfUser As RichTextBox, ParamFaultid As Byte, Optional flag As Boolean, Optional lstfile As ListBox) Dim fso As New FileSystemObject Dim newconnect As String newconnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sFile & ";Persist Security Info=False;Jet OLEDB:Database Password=" & CStr(G_Password) Dim repcn As ADODB.Connection Set repcn = New ADODB.Connection repcn.Open newconnect Dim mstream As ADODB.Stream Dim Index As Byte, PictureName As String Dim RsPic As New ADODB.Recordset 'for opening recordset Cn.Execute "Delete from Chunks "
RsPic.Open "Select test_definition_id,FAULT_TYPE,photo,Under_Over_Type from chunks", repcn, adOpenKeyset, adLockOptimistic If flag = False Then For Index = 0 To ParamFaultid PictureName = ReportDefinitionID & Index & ".jpg" If fso.FileExists(DBnameFolder & "\" & PictureName) Then Set mstream = New ADODB.Stream mstream.Type = adTypeBinary mstream.Open mstream.LoadFromFile DBnameFolder & "\" & PictureName
RsPic.AddNew RsPic.Fields("photo").Value = mstream.Read RsPic.Fields(0) = ReportDefinitionID RsPic("Fault_Type") = Index RsPic("under_over_type") = 0 RsPic.Update mstream.Flush mstream.Close Set mstream = Nothing End If Next End If If flag = True Then
For Index = 0 To 1 PictureName = ReportDefinitionID & Index & ".jpg" If fso.FileExists(DBnameFolder & "\" & PictureName) Then Set mstream = New ADODB.Stream mstream.Type = adTypeBinary mstream.Open mstream.LoadFromFile DBnameFolder & "\" & PictureName RsPic.AddNew RsPic.Fields("photo").Value = mstream.Read RsPic.Fields(0) = ReportDefinitionID RsPic("Fault_Type") = 0 RsPic("under_over_type") = Index RsPic.Update mstream.Flush mstream.Close Set mstream = Nothing End If Next
End If
Err.CLEAR rtfOrig.text = "" rtfUser.text = "" repcn.Execute "delete from Chunks_TestDefinition_NoteBook" rsrelaynotebook.Close Set rsrelaynotebook = Nothing Set rsrelaynotebook = New ADODB.Recordset rsrelaynotebook.Open "select * from Chunks_TestDefinition_NoteBook", repcn, adOpenDynamic, adLockOptimistic If fso.FileExists(DBNoteBookFolder & "\" & "TD_O" & ReportDefinitionID & ".rtf") Then rtfOrig.LoadFile DBNoteBookFolder & "\" & "TD_O" & ReportDefinitionID & ".rtf" End If
If fso.FileExists(DBNoteBookFolder & "\" & "TD_U" & ReportDefinitionID & ".rtf") Then rtfUser.LoadFile DBNoteBookFolder & "\" & "TD_U" & ReportDefinitionID & ".rtf" End If rsrelaynotebook.AddNew rsrelaynotebook(0) = ReportDefinitionID rsrelaynotebook(2) = rtfOrig.text rsrelaynotebook(1) = rtfUser.text rsrelaynotebook(3) = Tattached_files rsrelaynotebook.Update repcn.Close Set repcn = Nothing Set fso = Nothing Set rsrelaynotebook = Nothing End Sub
Just go thr this link for more details;
http://visualbasic.ittoolbox.com/groups/technical-functional/vb-crystalreports-l/printing-pictures-in-crystal-reports-80-247818#
http://www.tech-archive.net/Archive/VB/microsoft.public.vb.crystal/2006-08/msg00136.html
Here are some links realated to crystal report just go thr this;
http://www.codeguru.com/forum/archive/index.php/f-64-p-9.html
Best Luck!!!!!!!!!!!!!! Sujit. |
 |
| |
Binary format |
| sri sri replied to Atheeq Ahmed at Monday, June 16, 2008 1:31 AM |
Hi, you have to convert your image file to binary format and you have to pass to the crystal report. try the below code
DataTable dt = new DataTable();
DataRow drow; // add the column in table to store the image of Byte array type
dt.Columns.Add("Image", System.Type.GetType("System.Byte[]")); drow = dt.NewRow; FileStream fs; BinaryReader br;
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "1.Jpg")) { // open image in file stream
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "1.Jpg", FileMode.Open); } else { // if phot does not exist show the nophoto.jpg file
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "NoImage.jpg", FileMode.Open); }
br = new BinaryReader(fs); byte[] imgbyte = new byte[fs.Length + 1]; imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length))); drow(0) = imgbyte;
dt.Rows.Add(drow); br.Close(); fs.Close(); CrystalReport1 rptobj = new CrystalReport1(); rptobj.SetDataSource(dt); CrystalReportViewer1.ReportSource = rptobj;
|
 |
| |
How to print Picture in Crystal Report 8.5 |
| Swapnil Salunke replied to Atheeq Ahmed at Monday, June 16, 2008 1:35 AM |
 | Hello Atheeq Ahmed
You can try this way try { DataTable dt = new DataTable(); DataRow drow; dt.Columns.Add("Image", System.Type.GetType("System.Byte[]")); drow = dt.NewRow; FileStream fs; BinaryReader br; if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "10157.Jpg")) { fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "10157.Jpg", FileMode.Open); } else { fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "NoPhoto.jpg", FileMode.Open); } br = new BinaryReader(fs); byte[] imgbyte = new byte[fs.Length + 1]; imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length))); drow(0) = imgbyte; dt.Rows.Add(drow); br.Close(); fs.Close(); CrystalReport1 rptobj = new CrystalReport1(); rptobj.SetDataSource(dt); CrystalReportViewer1.ReportSource = rptobj; } catch (Exception ex) { Interaction.MsgBox("Missing 10157.jpg or nophoto.jpg in application folder"); }
|
 |
| |
try this... |
| Vasanthakumar D replied to Atheeq Ahmed at Monday, June 16, 2008 1:42 AM |
 | Hi,
you need to store the image directly into your database inorder to bind the crystal reposets directly to the database.
Otherwise you need to load the data into dataset. and do the below for each row in dataset
1. Get the stream reader for file metnined in the image path of the each row.
2. Read the stream and load it into the bytes.
3. Store the bytes in the Dataset
4. Pass this dataset to crystal reports as a data source.
here is the below link for showing images from various database
http://resources.businessobjects.com/support/communitycs/TechnicalPapers/cr_insert_images.pdf?recDnlReq=Record&dnlPath=cr_insert_images.pdf |
 |
| |
| change image at runtime |
| sundar k replied to Atheeq Ahmed at Monday, June 16, 2008 4:26 AM |
How to Change an image in the Crystal Report at runtime
http://www.c-sharpcorner.com/UploadFile/saj/CrystalReports03192006090510AM/CrystalReports.aspx
hope it helps! |
 |
| |
re: |
| alice johnson replied to Atheeq Ahmed at Monday, June 16, 2008 12:00 PM |
i mapped that feild in report.
Public Sub SaveReportPicture(rtfOrig As RichTextBox, rtfUser As RichTextBox, ParamFaultid As Byte, Optional flag As Boolean, Optional lstfile As ListBox) Dim fso As New FileSystemObject Dim newconnect As String newconnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sFile & ";Persist Security Info=False;Jet OLEDB:Database Password=" & CStr(G_Password) Dim repcn As ADODB.Connection Set repcn = New ADODB.Connection repcn.Open newconnect Dim mstream As ADODB.Stream Dim Index As Byte, PictureName As String Dim RsPic As New ADODB.Recordset 'for opening recordset Cn.Execute "Delete from Chunks "
RsPic.Open "Select test_definition_id,FAULT_TYPE,photo,Under_Over_Type from chunks", repcn, adOpenKeyset, adLockOptimistic If flag = False Then For Index = 0 To ParamFaultid PictureName = ReportDefinitionID & Index & ".jpg" If fso.FileExists(DBnameFolder & "\" & PictureName) Then Set mstream = New ADODB.Stream mstream.Type = adTypeBinary mstream.Open mstream.LoadFromFile DBnameFolder & "\" & PictureName
RsPic.AddNew RsPic.Fields("photo").Value = mstream.Read RsPic.Fields(0) = ReportDefinitionID RsPic("Fault_Type") = Index RsPic("under_over_type") = 0 RsPic.Update mstream.Flush mstream.Close Set mstream = Nothing End If Next End If If flag = True Then
For Index = 0 To 1 PictureName = ReportDefinitionID & Index & ".jpg" If fso.FileExists(DBnameFolder & "\" & PictureName) Then Set mstream = New ADODB.Stream mstream.Type = adTypeBinary mstream.Open mstream.LoadFromFile DBnameFolder & "\" & PictureName RsPic.AddNew RsPic.Fields("photo").Value = mstream.Read RsPic.Fields(0) = ReportDefinitionID RsPic("Fault_Type") = 0 RsPic("under_over_type") = Index RsPic.Update mstream.Flush mstream.Close Set mstream = Nothing End If Next
End If
Err.CLEAR rtfOrig.text = "" rtfUser.text = "" repcn.Execute "delete from Chunks_TestDefinition_NoteBook" rsrelaynotebook.Close Set rsrelaynotebook = Nothing Set rsrelaynotebook = New ADODB.Recordset rsrelaynotebook.Open "select * from Chunks_TestDefinition_NoteBook", repcn, adOpenDynamic, adLockOptimistic If fso.FileExists(DBNoteBookFolder & "\" & "TD_O" & ReportDefinitionID & ".rtf") Then rtfOrig.LoadFile DBNoteBookFolder & "\" & "TD_O" & ReportDefinitionID & ".rtf" End If
If fso.FileExists(DBNoteBookFolder & "\" & "TD_U" & ReportDefinitionID & ".rtf") Then rtfUser.LoadFile DBNoteBookFolder & "\" & "TD_U" & ReportDefinitionID & ".rtf" End If rsrelaynotebook.AddNew rsrelaynotebook(0) = ReportDefinitionID rsrelaynotebook(2) = rtfOrig.text rsrelaynotebook(1) = rtfUser.text rsrelaynotebook(3) = Tattached_files rsrelaynotebook.Update repcn.Close Set repcn = Nothing Set fso = Nothing Set rsrelaynotebook = Nothing End Sub |
 |
| |
| I need this coding in vb.net - Picture print in crystal rep 8,5 |
| Atheeq Ahmed replied to sri sri at Wednesday, June 18, 2008 1:38 AM |
Dear senthil kumar
Thanks for sending me coding for picture printing in crystal report
Can you please send me in vb.net format.
I already hv a picture path in my table similar to this the photo can be print in Crystal report.
Pls help
Atheeq
|
 |
| |
| Please help how to print picture in Crystal Report 8.5 from the given path |
| GULAM SHAIKH replied to Atheeq Ahmed at Monday, July 27, 2009 1:13 AM |
| D:\foto\george.jpg |
 |
| |
|
|