Thulasiram pakala

Thulasiram pakala

  • 900
  • 872
  • 116.6k

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 format what happened 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 database i am using this code and call pdf dll file anyone help
 
hear i am attaching coding what i need after storing jpeg files need to store in data base that all files in one id
  1. protected void btnPDFToImage_Click(object sender, EventArgs e)  
  2. {  
  3. string fn="";  
  4. try  
  5. {  
  6. if (FileUpload1.HasFile)  
  7. {  
  8. //first save pdf file in root folder  
  9. fn = FileUpload1.FileName;  
  10. FileUpload1.PostedFile.SaveAs(Server.MapPath("pdf/") + fn);  
  11. }  
  12. //pdf file path return for convert  
  13. string Path = Server.MapPath("pdf/" + fn);  
  14. string serverDirectory = Server.MapPath("E_journal_uploads");  
  15. string folderName = TextBox1.Text;  
  16. string directoryPath = serverDirectory + @"\" + folderName;  
  17. if (!Directory.Exists(directoryPath))  
  18. {  
  19. Directory.CreateDirectory(directoryPath);  
  20. // lblMessage.Text = "Directory created on server.";  
  21. }  
  22. else  
  23. {  
  24. lblMessage.Text = "Directory already exists.";  
  25. }  
  26. //path for save converted images  
  27. // string SaveImageToFolder = Server.MapPath("ConvertedImage");  
  28. PDFConvert Pconverter = new PDFConvert();  
  29. bool Converted = false;  
  30. Pconverter.JPEGQuality = 2000;  
  31. Pconverter.OutputFormat = "jpeg";  
  32. Pconverter.OutputToMultipleFile = true;  
  33. // Pconverter.Height = 2000;  
  34. // Pconverter.Width = 1526;  
  35. Pconverter.Height = 950;  
  36. Pconverter.Width = 750;  
  37. Pconverter.FitPage = true;  
  38. Pconverter.TextAlphaBit = 4;  
  39. System.IO.FileInfo input = new FileInfo(Path);  
  40. string output = string.Format("{0}\\{1}{2}", directoryPath, input.Name, ".jpeg");  
  41. Converted = Pconverter.Convert(input.FullName, output);  
  42. con.Open();  
  43. SqlCommand cmd = new SqlCommand("Insert into Journals(Journal_ID,imagepath) values(@Journal_ID,@ImagePath)", con);  
  44. //Passing parameters to query  
  45. //int i = 1;  
  46. // i++;  
  47. cmd.Parameters.AddWithValue("@Journal_ID", folderName);  
  48. cmd.Parameters.AddWithValue("@ImagePath", directoryPath);  
  49. // cmd.Parameters.AddWithValue("@ImagePath", "E_journal_uploads/" + folderName +input.Name+i+".Jpeg");  
  50. cmd.ExecuteNonQuery();  
  51. con.Close();  
  52. input.Delete();//delete pdf file after converted!!!  
  53. lblMsg.Text = "Pdf converted into images successfully!Check folder";  
  54. }  
  55. catch (Exception ex)  
  56. {  
  57. lblMsg.ForeColor = System.Drawing.Color.Red;  
  58. lblMsg.Text = "an error occured.<br />";  
  59. lblMsg.Text = ex.Message;  
  60. }  

Attachment: pdf.rar

Answers (4)