1. nuget 安装插件
2. 上代码
// Define method to convert PDF to PNG public void ConvertPdfToPng(string pdfFilePath, string pngFileFolder, ImageFormat format) { // Set resolution (DPI) int dpi = 300; // Render PDF to image using (var document = PdfDocument.Load(pdfFilePath)) { for (int i = 0; i < document.PageCount; i++) { Thread.Sleep(100); using (var image = document.Render(i, dpi, dpi, PdfRenderFlags.CorrectFromDpi)) { var encoder = ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == format.Guid); var encParams = new EncoderParameters(1); encParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 10L); //高质量 image.Save(pngFileFolder + i + ".png", encoder, encParams); } } } }
3. 调用即可
ConvertPdfToPng(inputPdfPath, outputImageFolder, ImageFormat.Png);
标签:插件,asp,image,var,pdf,encParams,dpi From: https://www.cnblogs.com/haoliansheng/p/17296588.html