我想阅读我的PDF的所有页面并将它们保存为图像,到目前为止我所做的只是让我首先定义0 = 1
等页面。我是否有可能定义一个范围 ?
static void Main(string[] args)
{
try
{
string path = @"C:\Users\test\Desktop\pdfToWord\";
foreach (string file in Directory.EnumerateFiles(path, "*.pdf")) {
using (var document = PdfiumViewer.PdfDocument.Load(file))
{
int i = 1;
var image = document.Render(0,300,300, true);
image.Save(@"C:\Users\test\Desktop\pdfToWord\output.png", ImageFormat.Png);
}
}
}
catch (Exception ex)
{
// handle exception here;
}
答案 0 :(得分:6)
如果您的document-object为您提供了pagecount,
你可以替换
int i = 1;
var image = document.Render(0,300,300, true);
image.Save(@"C:\Users\test\Desktop\pdfToWord\output.png", ImageFormat.Png);
通过
for(int index = 0; index < document.PageCount; index++)
{
var image = document.Render(index,300,300, true);
image.Save(@"C:\Users\test\Desktop\pdfToWord\output"+index.ToString("000")+".png", ImageFormat.Png);
}