[英]Read all pages from PDF c#
I want to read all pages of my PDF and save them as a images, so far what I am doing is only getting me the page defined 0 = 1
first etc .. Is there a chance that I can define a range ? 我想阅读我的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;
}
if your document-object gives you the pagecount, 如果您的document-object为您提供了pagecount,
you could replace 你可以替换
int i = 1;
var image = document.Render(0,300,300, true);
image.Save(@"C:\Users\test\Desktop\pdfToWord\output.png", ImageFormat.Png);
by 通过
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.