private void ExtractImage() { int h = 1; string[] ImageName = new string[TongSoTrang + 1]; foreach (DataGridViewRow dr in dataGridView1.Rows) { string temp = ""; string[] temp1 = null; if (h < dataGridView1.RowCount) { temp = dr.Cells[2].Value != null ? dr.Cells[2].Value.ToString() : ""; if (temp.IndexOf(";", StringComparison.Ordinal) > 0) { temp1 = temp.Split(';'); for (int i = 0; i < temp1.Length; i++) { if (temp1[i].IndexOf("-", StringComparison.Ordinal) > 0) { string[] temp2 = temp1[i].Split('-'); for (int j = int.Parse(temp2[0]); j <= int.Parse(temp2[1]); j++) { ImageName[j] = dr.Cells[1].Value.ToString(); } } else { ImageName[int.Parse(temp1[i])] = dr.Cells[1].Value.ToString(); } } } else { if (temp.IndexOf("-", StringComparison.Ordinal) > 0) { string[] temp2 = temp.Split('-'); for (int j = int.Parse(temp2[0]); j <= int.Parse(temp2[1]); j++) { ImageName[j] = dr.Cells[1].Value.ToString(); } } else { ImageName[int.Parse(temp)] = dr.Cells[1].Value.ToString(); } } } h++; } var f = new PdfFocus { Serial = "1234567890" }; string pdfFile = txt_ImagePath.Text; string imageDir = Path.GetDirectoryName(pdfFile); List <PdfFocus.PdfImage> pdfImages = null; f.OpenPdf(pdfFile); if (f.PageCount > 0) { pdfImages = f.ExtractImages(1, f.PageCount); // Show all extracted images. if (pdfImages != null && pdfImages.Count > 0) { for (int i = 0; i < pdfImages.Count; i++) { string imageFile = Path.Combine(txt_FolderSaveImage.Text + "\\", ImageName[i + 1] + "_Page" + (i + 1) + ".jpg"); pdfImages[i].Picture.Save(imageFile); } } } }