Thulasiram pakala

Thulasiram pakala

  • NA
  • 231
  • 31.8k

convertded pdf to image and store folder

Sep 22 2016 3:35 AM
Hi
        What i am doing i convert pdf files in to jpeg farmate what happend its  converted  one pdf page to one image file and store on one folder  what i need i need to store this all jpeg to data base   i am using this code and call pdfdll  file any one help 
 hear i am attaching coding what i need after stroring jpeg files need to store in data base that all files in one id
 
 
protected void btnPDFToImage_Click(object sender, EventArgs e)
{
string fn="";
try
{
if (FileUpload1.HasFile)
{
//first save pdf file in root folder
fn = FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath("pdf/") + fn);
}
//pdf file path return for convert
string Path = Server.MapPath("pdf/" + fn);
string serverDirectory = Server.MapPath("E_journal_uploads");
string folderName = TextBox1.Text;
string directoryPath = serverDirectory + @"\" + folderName;
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
// lblMessage.Text = "Directory created on server.";
}
else
{
lblMessage.Text = "Directory already exists.";
}
//path for save converted images
// string SaveImageToFolder = Server.MapPath("ConvertedImage");
PDFConvert Pconverter = new PDFConvert();
bool Converted = false;
Pconverter.JPEGQuality = 2000;
Pconverter.OutputFormat = "jpeg";
Pconverter.OutputToMultipleFile = true;
// Pconverter.Height = 2000;
// Pconverter.Width = 1526;
Pconverter.Height = 950;
Pconverter.Width = 750;
Pconverter.FitPage = true;
Pconverter.TextAlphaBit = 4;
System.IO.FileInfo input = new FileInfo(Path);
string output = string.Format("{0}\\{1}{2}", directoryPath, input.Name, ".jpeg");
Converted = Pconverter.Convert(input.FullName, output);
con.Open();
SqlCommand cmd = new SqlCommand("Insert into Journals(Journal_ID,imagepath) values(@Journal_ID,@ImagePath)", con);
//Passing parameters to query
//int i = 1;
// i++;
cmd.Parameters.AddWithValue("@Journal_ID", folderName);
cmd.Parameters.AddWithValue("@ImagePath", directoryPath);
// cmd.Parameters.AddWithValue("@ImagePath", "E_journal_uploads/" + folderName +input.Name+i+".Jpeg");
cmd.ExecuteNonQuery();
con.Close();
input.Delete();//delete pdf file after converted!!!
lblMsg.Text = "Pdf converted into images successfully!Check folder";
}
catch (Exception ex)
{
lblMsg.ForeColor = System.Drawing.Color.Red;
lblMsg.Text = "an error occured.<br />";
lblMsg.Text = ex.Message;
}
 

Attachment: pdf.rar

Answers (2)