Solved

Converting Images from Tiff from 1 database to Tiff 2nd database

Posted on 2004-09-27
12
719 Views
Last Modified: 2008-01-09
I ahve an Code for converting Images from tiff to PDF when it transfers to 2nd db.
I have to chnage such a way that Tiff images to go as Tiff's to 2nd databae.
What are the lines i have to change to make this happen. No conversion to PDF. Only it has to convert to PDF when User click on the image hyperlink.But DB has to have as tiff's

Thanks
Sunni
0
Comment
Question by:sunniunda
12 Comments
 

Author Comment

by:sunniunda
ID: 12164531
This is the code that converts to PDF's
//convert current tiff image to PDF using Memory Stream                                                                  
                                          ceTe.DynamicPDF.Document objNewPDF = new ceTe.DynamicPDF.Document();
                                          ceTe.DynamicPDF.PageElements.Image img = new ceTe.DynamicPDF.PageElements.Image(@varImage, 0,0,1);
                                                PageDimensions objPageDimensions = new PageDimensions(img.Width,img.Height,0.25f);
                                          ceTe.DynamicPDF.Page objPage = new ceTe.DynamicPDF.Page(objPageDimensions);
                                          //                  img.Align = ceTe.DynamicPDF.Align.Center;
                                          //                  img.VAlign = ceTe.DynamicPDF.VAlign.Center;
                                          img.SetBounds (img.Width, img.Height);
                                          objPage.Elements.Add(img );
                                          MemoryStream objStream = new MemoryStream();
                                          //FileStream objStream = new FileStream(@"C:\NewPDF.pdf",FileMode.OpenOrCreate);
                                          objNewPDF.Pages.Add(objPage);
                                    
                                          objNewPDF.Draw(objStream);
                                          byte [] bytImage = objStream.ToArray();
                                          objStream.Close();

Please let me know, what are the lines that I have to change to transfer as Tiff's

Thanks
Sunni
0
 
LVL 34

Expert Comment

by:flavo
ID: 12166045
Can you just do a insert query?

ie

Insert into tblMyTable.Tiff (select tiff from tblOtherTable);
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12167735
None of the lines above are telling anything about saving the object in a database.. All of them concerns the chnage from TIFF to PDF,
Probably code would be after this function to place it in DB.
0
 

Author Comment

by:sunniunda
ID: 12174552
armoghan,
I will send you the whole copy of the code
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;
using EasyAccess.Framework;
using System.Configuration;
using System.Web;
using System.Text;


namespace EasyAccessTeleformImporter
{
      /// <summary>
      /// This clas will import index values and images
      /// to the Easy Access 2 databases
      /// </summary>
      class EasyAccessImporter
      {

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main(string[] args)

            {
                  int intSessionID;
                  int intImporterIDTotal;
                  //Get SessionID

                  intSessionID = GetSessionID();
                  intImporterIDTotal = 0;

                  Console.WriteLine("Starting Easy Access V2 Importer " + DateTime.Now);

                  //Open connection to Scanned Data
                  SqlConnection cn = new SqlConnection( ConfigurationSettings.AppSettings["DSN"] );
                  cn.Open();

                  //Pull data for export by Document Type
                  SqlCommand cmd = new SqlCommand("usp_ProjectDocTypeSelect");
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.Connection = cn;
                  

                  SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                        // if Document Type ID exists for Import pull the data
                        while (dr.Read() )
                        {      intImporterIDTotal= 0;
                              intImporterIDTotal = ProjectDocTypeImport(
                                    intSessionID,
                                    Convert.ToInt32(dr["ImporterID"]),
                                    Convert.ToInt32(dr["ProjectDocTypeID"]),
                                    Convert.ToInt32(dr["EA_DocTypeID"]),
                                    dr["ImportConnectionString"].ToString());
                                                      
                              RecordImportStatistics(intSessionID, Convert.ToInt32(dr["ImporterID"]), intImporterIDTotal);
                              Console.WriteLine ("Imported for Document Type ID: " + dr["ProjectDocTypeID"] +  "  Total: " + intImporterIDTotal);
                        }

                        ReportImportStatistics(intSessionID);
                        Console.WriteLine ("Session ID: " + intSessionID +  "  completed. Email report sent! ");

                        cmd.Dispose();
                        cmd = null;

                        cn.Dispose();
                        cn = null;
            }

            private static int ProjectDocTypeImport (int intSessionID, int ImporterID, int ProjectDocTypeID, int EA_DocTypeID, string ConnectionString )
            {
                  int intPageCount;
                  int intDocPagesCount;
                  bool bln;
                  int intImportTotal;
                  int i;
                  int intIndexCount;
                  object objIndexValue;
                  int      intIndexID;
                  
                  //pull available data for DocType ID
                  SqlConnection cn = new SqlConnection( ConfigurationSettings.AppSettings["DSN"] );
                  cn.Open();

                  SqlCommand cmd = new SqlCommand("usp_ScanSelect");
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.Connection = cn;

                  cmd.Parameters.Add("@ProjectDocTypeID", ProjectDocTypeID);
                  SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);


                  try
                  {
                        Doc docNew = new Doc(ConnectionString);
                        EasyAccess.Framework.Page pNew = new EasyAccess.Framework.Page(ConnectionString);
                        IndexName inSelected = new IndexName(ConnectionString);




                        //Loop through with the insert of documents and pages
                        intImportTotal = 0;
                        while (dr.Read() )
                        {
                              //Need to account for multipages inside the document
                              //convert the image to the PDF then to binary
                              intPageCount = 0;
                              intDocPagesCount = Convert.ToInt16(dr["Multipage"]);


                              docNew.Clear();
                              docNew.DocTypeID = EA_DocTypeID ;
                              docNew.ScanID = Convert.ToInt64(dr["ScanID"]);
                              docNew.ScanDate = Convert.ToDateTime(dr["ScanDate"]);
                              docNew.BatchID = Convert.ToString(dr["BatchID"]);
                              docNew.PickupDate = Convert.ToDateTime(dr["PickupDate"]);
                              docNew.Status = 1;
                              docNew.CreatedBy= 2;


                              for (intPageCount = 0; intPageCount < intDocPagesCount + 1 ; intPageCount ++)
                              {
                                    //find the tif file
                                    string varImageName = dr["ImageName"].ToString().Substring(0, 6);
                                    string varImageCount = Convert.ToString(intPageCount).PadLeft(4,'0');
                                    string varImage = Convert.ToString(dr["ImageLocation"]) + "\\" + varImageName + varImageCount + ".tif" ;
                                    bln = File.Exists(varImage);
                              
                                    if (bln)
                                    {
                                    
                                          //convert current tiff image to PDF using Memory Stream                                                                  
                                          ceTe.DynamicPDF.Document objNewPDF = new ceTe.DynamicPDF.Document();
                                          ceTe.DynamicPDF.PageElements.Image img = new ceTe.DynamicPDF.PageElements.Image(@varImage, 0,0,1);
                                                PageDimensions objPageDimensions = new PageDimensions(img.Width,img.Height,0.25f);
                                          ceTe.DynamicPDF.Page objPage = new ceTe.DynamicPDF.Page(objPageDimensions);
                                          //                  img.Align = ceTe.DynamicPDF.Align.Center;
                                          //                  img.VAlign = ceTe.DynamicPDF.VAlign.Center;
                                          img.SetBounds (img.Width, img.Height);
                                          objPage.Elements.Add(img );
                                          MemoryStream objStream = new MemoryStream();
                                          //FileStream objStream = new FileStream(@"C:\NewPDF.pdf",FileMode.OpenOrCreate);
                                          objNewPDF.Pages.Add(objPage);
                                    
                                          objNewPDF.Draw(objStream);
                                          byte [] bytImage = objStream.ToArray();
                                          objStream.Close();

                                          // INST DOCUMENT


      
                                          if (intPageCount == 0) // Document level
                                          {
                                                //Insert Document
                                                      docNew.Add();
                                                      
                                                      //calculate the import total
                                                      intImportTotal = intImportTotal + 1;

                                                      
                                                intIndexCount = 15;
                                                //Insert Indexes - each rows starts index population from column 14
                                                //till the end of the row. The idea is to set the insert statement
                                                //at every other column
                                                for (i = 0 ; i <=  (dr.FieldCount - (15 + 1))/2; i ++)
                                                {
                                                      objIndexValue = dr.GetValue(intIndexCount);
                                                      intIndexID = Convert.ToInt32(dr.GetValue(++ intIndexCount ));

                                                      //The insert is specified based on the Index Value type
                                                      inSelected.Load(intIndexID);
                                                      IndexValue ivNew = new IndexValue(inSelected,ConnectionString);
                                                      ivNew.DocID = docNew.DocID;
                                                      ivNew.Value = objIndexValue;//type 2

                                                      try
                                                      {
                                                            ivNew.Add();
                                                      }
                                                      catch
                                                      {
                                                            //Set to blank Invoice
                                                            ivNew.Value = "";
                                                            ivNew.Add();

                                                      }
                                                      finally
                                                      {
                                                            Console.WriteLine ("Error in index insert: Scan ID - " + docNew.ScanID +  "  Index Value - " + ivNew.Value );


                                                            dr.Close();
                                                            dr = null;

                                                            cmd.Dispose();
                                                            cmd = null;

                                                            cn.Dispose();
                                                            cn = null;


                                                      }
                                                      //increase the column count

                                                      intIndexCount ++;

                                                }

                                                //Update Document
                                                RecordImportStatusUpdate("P",intSessionID, "", Convert.ToInt32(dr["ScanID"]));
                                          }

                                          //Insert Page
                                          pNew.Clear();
                                          pNew.DocID = docNew.DocID;
                                          pNew.PageImage = bytImage;
                                          pNew.PageNumber = intPageCount + 1;
                                          pNew.ByteSize = bytImage.Length;
                                          pNew.CreatedBy = 2;
                                          pNew.Add();

                                          
                                    }
                                    else
                                    {
                                          //If image does not exist error should be recorded in the Scan based on the ScanID table
                                          RecordImportStatusUpdate("R",intSessionID, "Missing Image", Convert.ToInt32(dr["ScanID"]));
                                    }
                              

                              }
                        }

                  }

                  catch (Exception ex)
                  {
                        throw ex;
                  }

                  finally
                  {
                        dr.Close();
                        dr = null;

                  cmd.Dispose();
                  cmd = null;

                  cn.Dispose();
                  cn = null;
            
                  }
                  return intImportTotal;
            }


            private static void RecordImportStatusUpdate (string strImportStatus, int intImportSessionID, string strImportError, int intScanID)
            {
                  SqlConnection cn = new SqlConnection( ConfigurationSettings.AppSettings["DSN"] );
                  cn.Open();

                  SqlCommand cmd = new SqlCommand("usp_ScanUpdate");
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.Connection = cn;
                  try
                  {
                        cmd.Parameters.Add("@strImportStatus", strImportStatus);
                        cmd.Parameters.Add("@intImportSessionID", intImportSessionID);
                        cmd.Parameters.Add("@strImportError", strImportError);
                        cmd.Parameters.Add("@intScanID", intScanID);

                        cmd.ExecuteNonQuery();

                  }

                  catch (Exception ex)
                  {
                        throw ex;
                        
                  }
                  
                  finally
                  {
                        cmd.Dispose();
                        cmd = null;

                        cn.Dispose();
                        cn = null;
                  }
         }
            private static int GetSessionID()
            {
                  int SessionID;
                  
                  //open

                  SqlConnection cn = new SqlConnection( ConfigurationSettings.AppSettings["DSN"] );
                  cn.Open();

                  SqlCommand cmd = new SqlCommand("usp_GetNextID");
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.Connection = cn;
                  try
                  {
                        cmd.Parameters.Add("@IDType", "SessionID");
                        SessionID = Convert.ToInt32(cmd.ExecuteScalar());
                  }

                  catch (Exception ex)
                  {
                        throw ex;
                  }
                  
                  finally
                  {
                  
                        cmd.Dispose();
                        cmd = null;

                        cn.Dispose();
                        cn = null;
                  }
                  return SessionID;
            }

            private static void ReportImportStatistics(int intSessionID)
            {
                  //This function will get the session data and send the report
                  //to the EasyAccess group
                  //Create Connection to the Session Log table
                  //Pull data for the session ID
                  SqlConnection cn = new SqlConnection( ConfigurationSettings.AppSettings["DSN"] );
                  cn.Open();
                  
                  //Create Command
                  SqlCommand sqlCmd = new SqlCommand("usp_ImporterLogSelect");
                  sqlCmd.CommandType = CommandType.StoredProcedure;                  
                  sqlCmd.Connection = cn;

                  string strMsg = string.Empty;
                  //Beginning of the strMsg
                  strMsg += "Easy Access V2 Import Report" + "\r\n";
                  strMsg += "\r\n";
                  strMsg += "Client         Process - Date - Count" + "\r\n";
                  strMsg += "\r\n";
                  try
                  {
                        //Create Parameter      
                        sqlCmd.Parameters.Add("@intImportSessionID",intSessionID);
                        SqlDataReader dr = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection);

                        // if Document Type ID exists for Import pull the data
                        
                        while (dr.Read() )
                        {
                              strMsg += dr["Report"] + "\r\n";
                        }
                  }
                  catch ( Exception ex )
                  {
                        throw ex;

                  }
                  
                  finally
                  {
                        sqlCmd.Dispose();
                        sqlCmd = null;

                        cn.Dispose();
                        cn = null;
                  }

                  System.Web.Mail.MailMessage objMessage = new System.Web.Mail.MailMessage();
                  objMessage.Body = strMsg;
                  objMessage.Subject = "Easy Access Import Report";
                  objMessage.From = "Easyaccessimport@corporatesvcs.net";
                  System.Web.Mail.SmtpMail.SmtpServer = "SMTP.corporatesvcs.net";
                  objMessage.To = "Easyaccessimport@corporatesvcs.net";
                  System.Web.Mail.SmtpMail.Send( objMessage );
            }
            private static void RecordImportStatistics(int intSessionID, int intImporterID, int intImporterIDTotal)

            {
                  //Create Connection
                  SqlConnection cn = new SqlConnection( ConfigurationSettings.AppSettings["DSN"] );
                  cn.Open();
                  
                  //Create Command
                  SqlCommand sqlCmd = new SqlCommand("usp_ImporterLogInsert");
                  sqlCmd.CommandType = CommandType.StoredProcedure;                  
                  sqlCmd.Connection = cn;
                  try
                  {
                        //Create Parameter      
                        sqlCmd.Parameters.Add("@intImportSessionID",intSessionID);
                        sqlCmd.Parameters.Add("@intImporterID",intImporterID);
                        sqlCmd.Parameters.Add("@intImportTotal", intImporterIDTotal);

                        sqlCmd.ExecuteNonQuery();
                  }
                  catch ( Exception ex )
                  {
                        throw ex;

                  }
                  
                  finally
                  {
                        sqlCmd.Dispose();
                        sqlCmd = null;

                        cn.Dispose();
                        cn = null;
                  }
            }
            
      }
}

I just want to change the conversion to import Tiff image instead of PDF image. We used Dynamic PDF converter to convert. i do not want to use that.I just want to transfer tiff to tiff.
I think instead of memory stream I have to use File Stream.
Please suggest and help me get through this.
thanks
sunni
0
 
LVL 18

Accepted Solution

by:
armoghan earned 115 total points
ID: 12176744
What I have understood so far is that The code is converting from TIFF to PDF and then saving it in DB,
You want to get the TIFF and save it to DB with out converting..

what I could see is that the code underneith is doing the conversion, if you remove it and and instead of giving PDF file just give the TIFF file it will solve the problem

////////////Code to remove //////////
   //convert current tiff image to PDF using Memory Stream                                                      
                                   ceTe.DynamicPDF.Document objNewPDF = new ceTe.DynamicPDF.Document();
                                   ceTe.DynamicPDF.PageElements.Image img = new ceTe.DynamicPDF.PageElements.Image(@varImage, 0,0,1);
                                        PageDimensions objPageDimensions = new PageDimensions(img.Width,img.Height,0.25f);
                                   ceTe.DynamicPDF.Page objPage = new ceTe.DynamicPDF.Page(objPageDimensions);
                                   //               img.Align = ceTe.DynamicPDF.Align.Center;
                                   //               img.VAlign = ceTe.DynamicPDF.VAlign.Center;
                                   img.SetBounds (img.Width, img.Height);
                                   objPage.Elements.Add(img );
                                   MemoryStream objStream = new MemoryStream();
                                   //FileStream objStream = new FileStream(@"C:\NewPDF.pdf",FileMode.OpenOrCreate);
                                   objNewPDF.Pages.Add(objPage);
                             
                                   objNewPDF.Draw(objStream);
                                   byte [] bytImage = objStream.ToArray();
                                   objStream.Close();

                                   // INST DOCUMENT


     
                                   if (intPageCount == 0) // Document level
                                   {
                                        //Insert Document
                                             docNew.Add();
                                             
                                             //calculate the import total
                                             intImportTotal = intImportTotal + 1;

                                             
                                        intIndexCount = 15;
                                        //Insert Indexes - each rows starts index population from column 14
                                        //till the end of the row. The idea is to set the insert statement
                                        //at every other column
                                        for (i = 0 ; i <=  (dr.FieldCount - (15 + 1))/2; i ++)
                                        {
                                             objIndexValue = dr.GetValue(intIndexCount);
                                             intIndexID = Convert.ToInt32(dr.GetValue(++ intIndexCount ));

                                             //The insert is specified based on the Index Value type
                                             inSelected.Load(intIndexID);
                                             IndexValue ivNew = new IndexValue(inSelected,ConnectionString);
                                             ivNew.DocID = docNew.DocID;
                                             ivNew.Value = objIndexValue;//type 2

                                             try
                                             {
                                                  ivNew.Add();
                                             }
                                             catch
                                             {
                                                  //Set to blank Invoice
                                                  ivNew.Value = "";
                                                  ivNew.Add();

                                             }
                                             finally
                                             {
                                                  Console.WriteLine ("Error in index insert: Scan ID - " + docNew.ScanID +  "  Index Value - " + ivNew.Value );


                                                  dr.Close();
                                                  dr = null;

                                                  cmd.Dispose();
                                                  cmd = null;

                                                  cn.Dispose();
                                                  cn = null;


                                             }
                                             //increase the column count

                                             intIndexCount ++;

                                        }


///////////Code to remove //////////

////////////////and add this code/////////////////

FileStream objStream = new FileStream(varImage,FileMode.OpenOrCreate);
byte [] bytImage = objStream.ToArray();

/////////////////////////

I have not tested it, but you can workaround with this idea and solve the problem



0
 

Author Comment

by:sunniunda
ID: 12176822
armorghan,
Once I solve this issue of transferring the images as Tiff's. I have one more question. I will post as seperate question with different user Id. But I want to mention it to you though.
After the images are transfered as tiff to 2nd database. I want to show the useras Pdf when User access the Image. I want to show as Pdf version fg image and there are multiple images for 1 document. And there is a download documents Button, where user clicks that button to download all images for one document into 1 pdf document.
Is it possible to do this. My company already bought the software for converting Dynamic PDf Generator  and Dynamic Pdf Merger.
I just have to program to make it work when user clicks on Image using those software. I have to show it as Pdf.
Right now Code is rewritten for diplaying pdf document from taking Pdf version from DB.
Can you please help me on this. I will tell U in next post where I will post the code and question.
Once I figure out how to get Tiff image to 2nd database.

Thanks a lot for your response.
Sunni
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:sunniunda
ID: 12176870
armorghan,
I am getting an error when I debug the program with pasting the lines that you provided and commented out only the converting the Pdf part.
The error is
C:\Visual Studio Projects\EasyAccessTeleformImporter\EasyAccessImporter.cs(163): 'System.IO.FileStream' does not contain a definition for 'ToArray'

Please help me resolve this issue.
Thanks
Sunni
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12177500
ohh sorry FileStream doesnot have ToArray
use it like this
FileStream objStream = new FileStream(varImage,FileMode.OpenOrCreate);
           BinaryReader br = new BinaryReader(objStream );

byte [] bytImage = br.ReadBytes((int)objStream.Length);
            br.Close();
            objStream.Close();
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12177514
or this may also work
FileStream objStream = new FileStream(varImage,FileMode.OpenOrCreate);
byte [] bytImage = new  byte[objStream.Length];
                  
objStream.Read(bytImage,0,(int)objStream.Length);      
0
 

Author Comment

by:sunniunda
ID: 12179943
armoghan,
Thanks alot for your response.
I got error the error is
An unhandled exception of type 'System.NullReferenceException' occurred in EasyAccessTeleformImporter.exe

Additional information: Object reference not set to an instance of an object.

When I debug the program. It is going to line
Error in index insert: Scan ID - " + docNew.ScanID +  "  Index Value - " + ivNew.Value

Please help me armoghan.
I'll appreciate your help
Thanks
Sunni
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12186780
Actually I cannot test it as I dont have the PDF component and the DB


remove this
ivNew.Value
you dont need it anymore
0
 

Expert Comment

by:chinnipillu
ID: 12194202
This program is taking care of by somebody in my group to get the Tiff from 11 DB to 2nd DB.
Now i have to Dynamic Pdf generatpr to convert images from tiff to PDf on the fly . I have posted the message in .Net Can you please help me with that.
The question Title is

Converting Tiff image to Pdf image on the fly when User view the image from the frontend application using the software already purchased cete.Dynamic Pdf Generator and Merger

Please help me armoghan

Thanks
Sunni
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now