|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using O2S.Components.PDFRender4NET;
-
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
-
- namespace Common.system
- {
-
-
-
-
-
-
-
-
- public class PdfTrunImage
- {
- public enum Definition
- {
- One = 1, Two = 2, Three = 3, Four = 4, Five = 5, Six = 6, Seven = 7, Eight = 8, Nine = 9, Ten = 10
- }
-
-
-
-
-
-
-
-
-
-
-
- public static List<string> ConvertPDF2Image(string pdfInputPath, string imageOutputPath,
- string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, Definition definition)
- {
- List<string> images = new List<string>();
- try
- {
- PDFFile pdfFile = PDFFile.Open(pdfInputPath);
-
- if (!Directory.Exists(imageOutputPath))
- {
- Directory.CreateDirectory(imageOutputPath);
- }
-
-
- if (startPageNum <= 0)
- {
- startPageNum = 1;
- }
-
- if (endPageNum == 0 || endPageNum > pdfFile.PageCount)
- {
- endPageNum = pdfFile.PageCount;
- }
- if (startPageNum > endPageNum)
- {
- int tempPageNum = startPageNum;
- startPageNum = endPageNum;
- endPageNum = startPageNum;
- }
-
-
- for (int i = startPageNum; i <= endPageNum; i++)
- {
- Bitmap pageImage = pdfFile.GetPageImage(i - 1, 56 * (int)definition);
- string imgPath = imageOutputPath + imageName + i.ToString() + "." + imageFormat.ToString();
- pageImage.Save(imgPath, imageFormat);
- images.Add(imgPath);
-
- pageImage.Dispose();
- }
-
- pdfFile.Dispose();
- return images;
- }
- catch (System.Exception ex)
- {
- LogHelper.WriteErrLog("PDF转图片" +
- "【PdfTrunImage】" + ex.Message, ex);
- images = new List<string>();
- return images;
- }
- }
- }
- }
|