创建一个.NET工程,添加以下Nuget库:
PDFium.WindowsV2
PDFiumSharp
使用以下代码即可实现,将PDF的每一页转化为一张图片,JPG或PNG格式都可以。
cs
string pdfPath = @"test\doc.pdf";
var white = new PDFiumSharp.Types.FPDF_COLOR(255, 255, 255);
var pdfDoc = new PdfDocument(pdfPath);
int count = 1;
foreach (var page in pdfDoc.Pages)
{
PDFiumBitmap bmp = new PDFiumBitmap((int)page.Width, (int)page.Height, true);
bmp.FillRectangle(0, 0, bmp.Width, bmp.Height, white);
page.Render(bmp);
bmp.Save(@$"test\{count}.png");
bmp.Dispose();
count++;
}
pdfDoc.Close();